A problem about STA object that is stored in Session State
-
Hi! First,I write a class with C#.The class looks like this class CSharpClass { //class_imported_from_typelibrary is a coclass that imported from //the typelibrary using Tlbimp.exe //all interfaces of this coclass are derived from IUnknown class_imported_from_typelibrary m_comclass; //CSharpClassA and CSharpClassB are two classes written in C# CSharpClassA m_a; CSharpClassB m_b; …… …… } I use this CSharpClass in my ASP.NET project later.The code in Page_Load function looks like this: Page_Load() { private CSharpClass m_SharpClass; if(Session["MyObj"] == null) { m_SharpClass = new csharpclass(); m_SharpClass.Dosomething(); Session["MyObj"] = m_SharpClass } else { m_SharpClass = (csharpclass)Session["MyObj"]; m_SharpClass.Dosomething(); } } After I retrieve the m_SharpClass from Session state,using this statement(m_SharpClass = (csharpclass)Session["MyObj"]).I found that the two fields m_a and m_b in the m_SharpClass object are OK,but m_comclass is corrupted,from the "Watch Window" it's value is an InvalidCastException.I don't know why? How can I gain access to the STA object after store it in the Session State later? I have set the AspCompat attribute to true. Thank you for your reply!;P
-
Hi! First,I write a class with C#.The class looks like this class CSharpClass { //class_imported_from_typelibrary is a coclass that imported from //the typelibrary using Tlbimp.exe //all interfaces of this coclass are derived from IUnknown class_imported_from_typelibrary m_comclass; //CSharpClassA and CSharpClassB are two classes written in C# CSharpClassA m_a; CSharpClassB m_b; …… …… } I use this CSharpClass in my ASP.NET project later.The code in Page_Load function looks like this: Page_Load() { private CSharpClass m_SharpClass; if(Session["MyObj"] == null) { m_SharpClass = new csharpclass(); m_SharpClass.Dosomething(); Session["MyObj"] = m_SharpClass } else { m_SharpClass = (csharpclass)Session["MyObj"]; m_SharpClass.Dosomething(); } } After I retrieve the m_SharpClass from Session state,using this statement(m_SharpClass = (csharpclass)Session["MyObj"]).I found that the two fields m_a and m_b in the m_SharpClass object are OK,but m_comclass is corrupted,from the "Watch Window" it's value is an InvalidCastException.I don't know why? How can I gain access to the STA object after store it in the Session State later? I have set the AspCompat attribute to true. Thank you for your reply!;P