Page view counter

Null Reference Exception in SessionStateModule

Last post 03-26-2008 1:19 PM by royhiggs. 19 replies.

Sort Posts:

  • Null Reference Exception in SessionStateModule

    07-11-2007, 3:33 PM
    • Loading...
    • redundent
    • Joined on 10-23-2006, 2:45 PM
    • Manhattan
    • Posts 9
    • Points 15

    Hi,

     I am receiving a null reference exception in SessionStateModule.PollLockedSessionCallbacks(). It seems to be associated with Async Callbacks. If I view my web page and refresh a couple of times, the AppDomain.CurrentDomain.UnhandledException is fired with the exception below.

    System.NullReferenceException: Object reference not set to an instance of an object.
        at System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(Object state)
        at System.Threading._TimerCallback.TimerCallback_Context(Object state)
        at System.Threading.ExecutionContext.runTryCode(Object userData)
        at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
        at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        at System.Threading._TimerCallback.PerformTimerCallback(Object state)

    The exception is terminating the asp worker process which is causing me problems.

    I am using ASP.NET 2.0 with ASP.NET Ajax.

    Any help will be greatly appreciated.

     

    Thank you,

    Jason Blackwell
     


     

    -Jason

    Now you're a man!
    Filed under: ,
  • Re: Null Reference Exception in SessionStateModule

    07-13-2007, 12:12 AM
    Answer

    HI, Jason Blackwell 

    This was probably caused by using Sql Server Session state and . The resolution was to use Inproc session state for
    debugging.

    You can  look at the machine.config, which was the only config file above this
    web.config in the hierarchy. Make sure the sql state was specified to InProc.

    If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.

    I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be

    of assistance

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: Null Reference Exception in SessionStateModule

    07-13-2007, 12:42 PM
    • Loading...
    • redundent
    • Joined on 10-23-2006, 2:45 PM
    • Manhattan
    • Posts 9
    • Points 15

     Rex,

     
    Thanks for your reply.

     The session state is currently set to InProc in the web.config and machine.config. None of the pages use session so turning off session state is an option and does fix the problem but I would like to know exactly why this is happening. It only started happening on Wednesday (7/11) after the windows update for .NET was applied so I'm wondering if it could possibly have something to do with that.

    The exception that is thrown is logged in the event viewer of the server. It is pasted below.
     EventType clr20r3, P1 aspnet_wp.exe, P2 2.0.50727.832, P3 461ef1db, P4 system.web, P5 2.0.0.0, P6 461ef1d2, P7 297c, P8 8d, P9 system.nullreferenceexception, P10 NIL.
     

     If you need anymore information from me please let me know. I really want to get to the bottom of this.

     

    Thanks. 

    -Jason

    Now you're a man!
  • Re: Null Reference Exception in SessionStateModule

    07-19-2007, 6:31 PM
    Answer
    • Loading...
    • jaymar10
    • Joined on 07-19-2007, 10:28 PM
    • Posts 1
    • Points 12

    I had the exact same issue along with many of the developers on my team.  We removed the Security Update for .NET Framework 2.0 (KB928365) from our machines and the problem went away. Your hunch was correct and most helpful!  The web is loaded with various issues that this "fix" is causing.

  • Re: Null Reference Exception in SessionStateModule

    08-14-2007, 9:25 AM
    • Loading...
    • redundent
    • Joined on 10-23-2006, 2:45 PM
    • Manhattan
    • Posts 9
    • Points 15
    Does anyone know of a way to fix this besides turning off sessions or unintstalling the update?
    -Jason

    Now you're a man!
  • Re: Null Reference Exception in SessionStateModule

    08-20-2007, 1:00 PM
    • Loading...
    • buckeyes
    • Joined on 07-11-2007, 3:28 PM
    • Posts 4
    • Points 2

    Have you found a fix for this yet.  I have the same problem and the only fix we have found is to uninstall the update.  If we do find the solution, I will post it.

     Thanks.

  • Re: Null Reference Exception in SessionStateModule

    08-29-2007, 6:25 PM
    Answer
    • Loading...
    • codepounder
    • Joined on 08-29-2007, 10:00 PM
    • Posts 1
    • Points 12

    We have the same issue with an almost identical stack trace as in the original post. We also removed the KB928365 security patch and the problem went away, but we're at a point now where we are going to need to keep the patch installed.

    buckeyes has another post (http://forums.asp.net/t/1132290.aspx) with a possible solution, or at least a workaround. I'll need to investigate our code further to make sure we don't have that issue. That situation also involves AJAX. Is this primarily an AJAX issue then? Is there any further word from MSFT?

     Dan

  • Re: Null Reference Exception in SessionStateModule

    08-30-2007, 4:52 PM
    Answer
    • Loading...
    • MatthewP
    • Joined on 08-30-2007, 8:48 PM
    • Posts 1
    • Points 12

    We were able to fix this issue.  As it turns out, the problem was caused by our custom IIdentity object we use to track authenticated users.  I switched our code to use a static, thread-safe collection and pull authenticated users from this collection instead of the HttpContext.Current.User property.  Now, our app does not replace the FormsIdentity object, and we no longer experience an app-pool crash under heavy load, and we can leave the security patch in place.

  • Re: Null Reference Exception in SessionStateModule

    09-23-2007, 9:34 PM
    • Loading...
    • matthewerwin
    • Joined on 09-24-2007, 1:27 AM
    • Posts 1
    • Points 2

    The solution suggested by MatthewP worked identically in my situation. Initially I suspected that the problem was caused by the location of the session state or the type of data stored it in. Further investigation proved this to be due to impersonation issues - specifically the assignment of IIdentity based objects to Context.User or to Thread.CurrentPrincipal. I was predictably able to reproduce this by refreshing the page 3-4 times but did not see the issue occur as frequently in production environments. It does not appear the problem is specific to servers under load.

     My solution was to simply move any assignments to Context.User into Context.Session since impersonation could be done where needed rather than assigning it for the lifetime of execution. Likely a better solution all around.

  • Idea [Idea] Re: Null Reference Exception in SessionStateModule

    09-24-2007, 11:12 PM
    • Loading...
    • AndrewCushen
    • Joined on 10-27-2004, 4:49 PM
    • New York
    • Posts 87
    • Points 217

    Hi all-

    Just spent 4 hours struggling with this problem, including 2 hours after finding this thread; then another 3.5 hours on top of that, on the phone with MS Tech Support.

    I thought I would share what I learned, which includes another workaround.

    The workarounds suggested above were not an option for me for various reasons, and I was not using impersonation. My particular web application required a custom Security.Principal.

    So, the upshot, after 3 and a half hours with the MS Tech connected remotely to my dev PC, was this:

    Take the custom Security.Principal class out of the website project, and compile it as a Class library into a .DLL (assembly). Sign the .DLL with a Strong Name, and place it in the GAC. Adjust your code that references the custom Principal to call the code in its new location, if necessary- I wound up adding a Reference to the new assembly in my website project. No more problem!

    A side note: if you use a WebSetup project to install your website, as I did, you can have it place the assembly into the server's GAC for you, during the installation.

     

    There is apparently something about moving the code that deals with the IIdentity out of the main project (out of the process?), that avoids the issue.

     

    I thought this might help someone else struggling with this issue. There is NOTHING on the web about this issue other than this thread!

     

    Hope this helps someone,

    -Andrew

    Please remember when your post is solved, to "Mark as Answer" the post(s) that solved it!
  • Re: Null Reference Exception in SessionStateModule

    09-25-2007, 2:27 PM
    • Loading...
    • fred.f.chopin
    • Joined on 07-20-2006, 6:25 PM
    • Posts 3
    • Points 9

    I worked with MatthewP on this issue for our web application.  I called Microsoft for support on this issue and after analyzing three crash dumps from our application (running without MatthewP's fix so we could repro the error) they had a lot of info for me.  They initially stated that our custom IIdentity object was not serializing properly.  I implemented explicit serialization on this object and it continued to crash.  After analyzing the additional crash reports, Microsoft was able to supply me with an internal hotfix that fixes this issue.  It hasn't been released yet although they have informed me that they will be making it available for download in the near future.  It's ID is KB942086 and you'll need to call microsoft support to get it (as of this post, anyway) but this completely fixed the issue caused by KB928365 without the workaround that we were using and without the explicit serialization on our custom IIdentity object.

  • Re: Null Reference Exception in SessionStateModule

    09-26-2007, 2:07 PM
    • Loading...
    • AndrewCushen
    • Joined on 10-27-2004, 4:49 PM
    • New York
    • Posts 87
    • Points 217

    Fred-

    Thanks for the update. With your new info "in hand", I contacted the Tech who worked on my case, and he verified that, although the error message I received was not the same as the one in the KB article you mentioned about the Hotfix, that the Hotfix *was* applicable to my case. Thanks to you, I now have the Hotfix and can apply it.

    Incidentally, my Tech says he is the one who filed the bug which resulted in the Hotfix being developed. I wonder if you and I spoke to the same Tech? Small world if so.

    Thanks again,

    -Andrew

    Please remember when your post is solved, to "Mark as Answer" the post(s) that solved it!
  • Re: Null Reference Exception in SessionStateModule

    09-28-2007, 12:42 PM
    • Loading...
    • fred.f.chopin
    • Joined on 07-20-2006, 6:25 PM
    • Posts 3
    • Points 9

    The tech that I worked with was named Sunil, and he was very helpful in this.  I don't know if he is the one that initially filed the bug, but he did say that there were a few other incidents of this issue that had been reported so it's possible.  Also, he just informed me today that the KB942086 is now publicly available, here's the direct link: http://support.microsoft.com/kb/942086

  • Re: Null Reference Exception in SessionStateModule

    10-23-2007, 6:29 PM
    • Loading...
    • thxmike
    • Joined on 09-28-2006, 3:11 PM
    • Posts 6
    • Points 2

    We are experiencing the same issue. However, I went to the URL outlined to get the fix and it was not available. You have to call MS support.

  • Re: Null Reference Exception in SessionStateModule

    11-14-2007, 12:25 PM
    • Loading...
    • dear_vvr
    • Joined on 11-14-2007, 4:08 PM
    • Posts 8
    • Points 8

    I had the same problem (same stack trace) in XP machine and when I removed the security update KB928365,  the problem is solved.

    I had this problem only when the applicaiton uses the transactions. This problem is not related to any page.  Looks like occurs at Global.asax 

    But even I did the samething in Vista machine, (removed security update KB929916) the problem still persists. Is there anything else I need to do?  

    Thanks

Page 1 of 2 (20 items) 1 2 Next >