FIX: References to STA Objects That Are Stored in Session State May Become Corrupted If They Are Called from a Session_End Event
For a Microsoft .NET Framework 1.0 version of this article, see 827163.
This article has been archived. It is offered "as is" and will no longer be updated.
If you store your references to single-threaded apartment (STA) objects in session state, and you set the AspCompat attribute to true, the references may become corrupted or may become lost when you try to gain access to the objects from the Session_End event.
Note Typically, this problem may occur if you run the application under high loads or if you use a stress tool such as Application Center Test (ACT) when you run the application. When this problem occurs, you receive a "0x8004e005 Error" error message in the event log.
The problem occurs because the Session_End event does not have to run on the same thread that the session was created on. Because the STA object is no longer on the same thread that the session was created on, marshaling is required to gain access to the object. This behavior causes slow performance.
You can store STA objects in session state. However, Microsoft does not recommend that you do so. For more information, see the "References" section of this article.
This hotfix adds a new configuration setting to the Machine.config file. After you install the hotfix, the following application configuration is available.
By default, apartmentThreading is set to false. If you set apartmentThreading to true, the following behavior occurs:
<httpRuntime apartmentThreading=”true|false” />,
- All Session_Start events run on STA threads that correspond to the session ID, regardless of the target page or the handler.
- All Session_End events run on STA threads that correspond to the session ID.
- AspCompat becomes set to true for all pages, except for the pages that have AspCompat set explicitly to false.
This hotfix works for STA objects that are stored directly in session state. This hotfix also works for an STA object that is nested one level deep such as a .NET object that is stored in session state and that has a reference to an STA object. However, this hotfix does not work for STA objects that are stored more than one level deep.
Important This hotfix contains two types of packages: a Microsoft Windows Installer package, and an Optional Component Manager package (OCM). If you use Microsoft Windows Server 2003, you must specify that you require the Windows Server 2003 (OCM) update, because Windows Server 2003 File Protection monitors the .NET Framework 1.1 files. If you use an operating system other than Windows Server 2003, you must continue to use the Windows Installer package.
The OCM version of this hotfix is available in the following languages:
- English (ENU)
- Japanese (JPN)
- German (DEU)
- French (FRN)
To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.
The English version of this hotfix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
Date Time Version Size File name ------------------------------------------------------------------------ 18-Sep-2003 05:18 1.1.4322.947 258,048 Aspnet_isapi.dll 18-Sep-2003 05:18 1.1.4322.947 20,480 Aspnet_regiis.exe 18-Sep-2003 05:18 1.1.4322.947 32,768 Aspnet_state.exe 18-Sep-2003 05:18 1.1.4322.947 32,768 Aspnet_wp.exe 16-May-2003 01:49 33,522 Installpersistsqlstate.sql 16-May-2003 01:49 34,150 Installsqlstate.sql 18-Sep-2003 05:09 1.1.4322.947 94,208 Perfcounter.dll 19-Sep-2003 02:43 1.1.4322.947 1,216,512 System.dll 19-Sep-2003 02:40 1.1.4322.947 323,584 System.runtime.remoting.dll 19-Sep-2003 02:43 1.1.4322.947 1,253,376 System.web.dll 19-Sep-2003 02:42 1.1.4322.947 819,200 System.web.mobile.dll 19-Sep-2003 02:41 1.1.4322.947 569,344 System.web.services.dll 19-Sep-2003 02:44 1.1.4322.947 1,335,296 System.xml.dll 18-Sep-2003 05:13 14,472 Webuivalidation.js
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section of this article.
This hotfix package also includes a secondary hotfix. If you set AspCompat to true, and you set an STA object that is stored in session state to null, you may receive a "NullReferenceException" error message when you reload the page. To reproduce the secondary problem, paste the following code inside a Page_Load event.
When you visit this page the first time, the code runs correctly. However, if you reload the page, you receive a "NullReferenceException" error message from Microsoft ASP.NET and you cannot view the page again inthe current session.
Session["obj"] = new Object(); Session["obj"] = null;
[NullReferenceException: Object reference not set to an instance of an object.]System.Web.UnsafeNativeMethods.AspCompatOnPageStart(Object obj) +0System.Web.Util.AspCompatApplicationStep.OnPageStartSessionObjects() +90System.Web.UI.Page.ProcessRequestMain() +44If you set AspCompat to false, this behavior does not occur.
Steps to Reproduce the BehaviorTo reproduce the problem that appears in the "Symptoms" section of this article, follow these steps:
- Use Microsoft Visual Basic .NET to create a Visual Basic ActiveX DLL object.
Note If you mark the component as Unattended Execution (UE), the error still occurs.
- Create two functions in the DLL class:
- Create a function that returns a string.
- Create a function that takes a long parameter and that returns a LONG value. This function does a loop that adds numbers from 1 to the number that is passed to the function.
- Create a new Web Application project that has two .aspx pages (Page1.aspx and Page2.aspx).
- In the Global.asax file of the Session_Start event, use CreateObject to create an instance of the object that you created in step 1.
- In the Page_Load event of Page1.aspx, call either of the functions that you created in step 2 from the object that is stored in session state.
- Create a hyperlink to Page2.aspx in Page1.aspx.
- In the Page_Load event of Page2.aspx, call the Session.Abandon method.
- Use Application Center Test (ACT) to create a test that records the operation of viewing Page1.aspx and then viewing Page2.aspx.
- Run the test with ten users. See if error 0x8004e005 appears in the Event Viewer.
Note You may have to increase the number of users to reproduce the problem.
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
243543 INFO: Do Not Store STA Objects in Session or Application
243815 PRB: Storing STA COM Component in Session Locks Session Down to Single Thread
817005 FIX: Severe Performance Issues When You Bind Session State to Threads in ASPCompat Mode
Article ID: 827164 - Last Review: 02/27/2014 21:19:50 - Revision: 1.7
Microsoft .NET Framework 1.1, Microsoft Visual Studio .NET 2003 Enterprise Architect, Microsoft Visual Studio .NET 2003 Enterprise Developer, Microsoft Visual Studio .NET 2003 Academic Edition, Microsoft ASP.NET 1.1
- kbnosurvey kbarchive kbhotfixserver kbqfe kberrmsg kbnetframe100presp3fix kbfix kbqfe kbcode kbbug KB827164