Microsoft KB Archive/818612

= FIX: &quot;COM Object Can Not Be Used&quot; Error Message When You Use an STA COM Object That You Created by Using Server.CreateObject and Stored in Session Scope in a Different Web Page =

Article ID: 818612

Article Last Modified on 10/25/2005

-

APPLIES TO


 * Microsoft .NET Framework 1.0

-





SYMPTOMS
You create a single-threaded apartment (STA) COM object by using Server.CreateObject, and then you store this STA COM object in session scope. If you use this STA COM object from another Web page, you receive the following error message:

COM object that has been separated from its underlying RCW can not be used



RESOLUTION
Important To apply this hotfix, you must have the .NET Framework Service Pack 2 installed.

How to obtain the hotfix
This issue is fixed in the June 2003 ASP.NET Hotfix Package 1.1. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

821156 INFO: ASP.NET 1.1 June 2003 Hotfix Rollup Package

You cannot obtain this fix individually. You must install the rollup.

Note When you request this hotfix, you receive the rollup.

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 --  25-Apr-2003  03:19  1.0.3705.424    196,608  Aspnet_isapi.dll 25-Apr-2003 03:19                  510,714  Aspnet_perf2.ini 25-Apr-2003 03:15                    4,169  Aspnet_perf.h   25-Apr-2003  03:19                  513,302  Aspnet_perf.ini 25-Apr-2003 03:19  1.0.3705.424     24,576  Aspnet_regiis.exe 25-Apr-2003 03:19  1.0.3705.424     28,672  Aspnet_wp.exe 24-Apr-2003 15:49  1.0.3705.424     69,632  Corperfmonext.dll 24-Apr-2003 15:47  1.0.3705.424    303,104  Mscorjit.dll 25-Apr-2003 12:55  1.0.3705.424  1,953,792  Mscorlib.dll 24-Apr-2003 15:48  1.0.3705.424  2,269,184  Mscorsvr.dll 01-Aug-2002 18:38                       15  Smartnav.htm 17-Oct-2002 14:55                    8,728  Smartnav.js   24-Apr-2003  15:40                   10,284  Mscorlib.ldo 24-Apr-2003 15:48  1.0.3705.424  2,269,184  Mscorwks.dll 25-Apr-2003 12:59  1.0.3705.424  1,191,936  System.web.dll

This hotfix is also available for the German version of the Microsoft .NET Framework 1.0. This hotfix is also available for the French version of the Microsoft .NET Framework 1.0.

If you applied the hotfix in this article for Microsoft ASP.NET included with the .NET Framework 1.0, and if you upgraded to Microsoft ASP.NET included with the .NET Framework 1.1, apply the hotfix package from the following Microsoft Knowledge Base article:

821156 INFO: ASP.NET 1.1 June 2003 Hotfix Rollup Package

Additionally, if you upgraded to the .NET Framework 1.1, and if you experience the symptoms in this article, apply the hotfix package from this Microsoft Knowledge Base article.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
If you create an STA object by using Server.CreateObject (Attribute AspCompat =&quot;true&quot;), you can use the object only in the Web page that you created it for. If you store the object in session scope, and then you try to gain access to it from a different Web page, you receive the error message.

Additionally, if you implement the OnStartPage method and the OnEndPage method from your STA COM object, these methods are not called on your object in the second Web page.

Steps to reproduce the behavior
  Use the following sample code to create a Microsoft Visual Basic 6.0 COM object that has AspEventProblem.Class1 for the ProgId: Public Function Test As String Test = &quot;Hello from COM Object&quot; End Function  Use Microsoft Visual Basic .NET to create a new Web application. Create a Web Form named WebForm1.aspx .  Add a Button object to WebForm1.aspx that contains the following sample code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As    System.EventArgs) Handles MyBase.Load Session(&quot;mycomp&quot;) =Server.CreateObject(&quot;AspEventProblem.Class1&quot;) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect(&quot;webform2.aspx&quot;) End Sub   Create a Web Form named WebForm2.aspx that contains the following sample code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = Session(&quot;mycomp&quot;).Test End Sub </li> In your browser, view WebForm1, and then click Button1.</li> When WebForm2 appears, click Button1.</li></ol>

Keywords: kbbug kbfix kbqfe kbnetframe100presp3fix kbhotfixserver KB818612

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.