locked
Session exception terminates application pool RRS feed

  • Question

  • User-755513990 posted

    We are having occuring application pool crashes with folowing exception.

    Application: w3wp.exe

    Framework Version: v4.0.30319

    Description: The process was terminated due to an unhandled exception. Exception Info: System.NullReferenceException Stack:    at System.Collections.Specialized.NameObjectCollectionBase.BaseGet(Int32)    at System.Web.SessionState.SessionStateItemCollection.get_Item(Int32)    at System.Web.SessionState.HttpSessionStateContainer.get_Item(Int32)    at System.Web.Util.AspCompatApplicationStep.AnyStaObjectsInSessionState(System.Web.SessionState.HttpSessionState)    at System.Web.HttpApplicationFactory.FireSessionOnEnd(System.Web.SessionState.HttpSessionState, System.Object, System.EventArgs)    at System.Web.SessionState.SessionOnEndTargetWorkItem.RaiseOnEndCallback()    at System.Web.Util.WorkItem.CallCallbackWithAssert(System.Web.Util.WorkItemCallback)    at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(System.Object)    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()    at System.Threading.ThreadPoolWorkQueue.Dispatch()    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

    I have read the KB http://support.microsoft.com/kb/827164 that it can occur when you are storing STA objects in the session, but I don´t think we do. How can we solve this issue? Just setting apartmentThreading to true doesn´t feel right.

    Wednesday, January 9, 2013 2:00 PM

Answers

  • User-755513990 posted

    I have found the problem. It was a controller that was decorated with the attribute [SessionState(SessionStateBehavior.ReadOnly)], Since I removed that no errors has occured.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 28, 2013 5:35 AM

All replies

  • User-3279452 posted

    Why do you to store this objects in Session and not in Cache. I'm not sure, but may be for Session storage it must be serializable.

    Friday, January 11, 2013 2:44 AM
  • User-166373564 posted

    Hi tobias

    You could understand and diagnose an application pool crash first, and then learn how to best deal with it below,

    application pool crash

    application domains, application pools and unhandled exceptions

    hope it helps you,

    Kind regards

    Monday, January 14, 2013 2:00 AM
  • User-755513990 posted

    I have tested setting apartmentThreading to true but that didn't help. I havn't been able to get a crash dump yet. For some reason my initial try didn't caught the exception.

    Wednesday, January 16, 2013 3:06 AM
  • Wednesday, January 16, 2013 3:33 AM
  • User-755513990 posted

    I have enabled legacyUnhandledExceptionPolicy so the application pool won't crash but that doesn't solve the underlying problem.

    Wednesday, January 16, 2013 3:55 AM
  • User-861818263 posted

    Please give me answers for following questions :- 

    1) Are you using webfarm ?

    2)Are you using App fabric ?

    3) what are you storing in session ? any complex object ?

    4) Are you storing viewstate in session ?

    5) session stored in inmemory or using state server\SQl server ?

    Wednesday, January 16, 2013 4:02 AM
  • User-861818263 posted

    Please give me answers for following questions :- 

    1) Are you using webfarm ?

    2)Are you using App fabric ?

    3) what are you storing in session ? any complex object ?

    4) Are you storing viewstate in session ?

    5) session stored in inmemory or using state server\SQl server ?

    Wednesday, January 16, 2013 4:02 AM
  • User-755513990 posted

    1) We are using a load balancer but each request for an application is always served by same webserver.

    2) No.

    3) Mostly primitives but som more complex objects.

    4) No.

    Wednesday, January 16, 2013 4:42 AM
  • User-861818263 posted

    Please provide machine key in each webconfig.

    Please make sure machinekey should be same on all server. will solve your error.

    http://msdn.microsoft.com/en-us/library/ff649308.aspx

    Also check use full post :

    http://www.c-sharpcorner.com/UploadFile/gopenath/Page107182007032219AM/Page1.aspx

    Wednesday, January 16, 2013 4:45 AM
  • User-755513990 posted

    Is that really needed when all requests are served by the same server?

    Wednesday, January 16, 2013 4:49 AM
  • User-861818263 posted

    YES

    Wednesday, January 16, 2013 4:55 AM
  • User-755513990 posted

    It didn't help to add a machine key, still same error and the application pool crashes even if legacyUnhandledExceptionPolicy  is set.

    I have checked the crash dump and for some reason a entry in the session state becomes null. Obviously the SessionStateItemCollection isn't thread safe so I suppose the thread might be reading the value at the same time as some other is manipulationg it. However i can't see any other thread accessing it at the same time.

    Monday, January 21, 2013 2:46 AM
  • User-755513990 posted

    I have found the problem. It was a controller that was decorated with the attribute [SessionState(SessionStateBehavior.ReadOnly)], Since I removed that no errors has occured.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 28, 2013 5:35 AM