
March 22nd, 2002, 01:23 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 23
|
|
|
Using Session Variables with COM objects
<i><b>Originally posted by : Dan (dan@smeadlink.com)</b></i><br />I am creating a Session variable for a COM object in Global.asax and passing it on to another ASPX page. In that page I create a local variable of that object, set the value and then set the Session variable to that object. In another ASPX page I create a local variable of that object and set it equal to the Session variable object. When I try to reference a property from the new local variable, I get a Cast error. But if I usa a late bound reference to the Session variable object, I get the value I need. Any ideas?<br /><br />Here's the code:<br /><br />GLOBAL.ASAX.VB<br /> Dim oAppEngine As SLDBEng.RMAGDBEngine_obj<br /><br /> Session.Add("AppEngine", Nothing)<br />---------------------------------------<br />PAGE1.ASPX.VB<br /> Dim oAppEngine As New SLDBEng.RMAGDBEngine_obj()<br /> <br /> Session.Item("AppEngine") = oAppEngine<br /> oAppEngine = Session.Item("AppEngine") 'Set back to itself so I could verify the next line was getting the value of the Session variable<br /> Response.Write(oAppEngine.MinorVersion)<br />---------------------------------------<br />PAGE2.ASPX.VB<br /> Dim oAppEngine As SLDBEng.RMAGDBEngine_obj<br /><br /> oAppEngine = Session.Item("AppEngine")<br /> Response.Write(oAppEngine.MinorVersion) 'This will give the Cast Exception Error<br /> Response.Write(Session("AppEngine").MinorVersion) 'Using the late bound reference works<br /><br />Here's the error:<br /> System.InvalidCastException: QueryInterface for interface SLDBEng._RMAGDBEngine_obj failed.<br /><br />No idea why it references the object name with an underscore. The object does not have an underscore in the name.<br />
|