Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

Serailize RCW class OR IPersistStream call to RCW class question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Puncher - 19 Jan 2005 16:58 GMT
Hi.

I have a RCW class that was generated by the VS.NET2003 IDE when I added a
COM dll reference to my project. This all works fine when I call methods on
it. My initial problem is that in ASP.NET I would like to add this to the
Session object whilst using SQLServer as the session storage. Unfortunately,
as this required the RCW class to be serializable, this won't work, and
throws an exception saying you can't Serialize the Session state if it
contains objects that are MarshalByRef and the session state mode is
SQLServer.

So question 1 - Is there an easy way to make an RCW class serializable? (I'm
expecting this to be "No", but if you don't ask you don't get)

Question 2 - My COM dll is capable of storing its own state, via its
implementation of IPersistStream. After a lot of Googling I've added C#
definitions of IPersist and IPersistStream. If I have a class AAA which
contains an instance of  MyLib::IRCWClass which is marked as
NonSerializable, then I've set AAA to implement ISerializable, and in
GetObjectData() I have

   MemoryStream memstream = new MemoryStream();
   ComStream cstream = new ComStream(memstream);

   IPersistStream pStream = (IPersistStream)m_RCWClass;

   if ( pStream != null )
       pStream.Save( cstream, false );
   else
       Trace.WriteLine( "No IPersistStream" );

This throws the same exception when it calls Save. However if I change the
third line to

   IPersistStream pStream = m_RCWClass as IPersistStream;

This also throws the same exception. Is there any way to gain access to the
IPersistStream methods, and then serialize the contents of my stream?

Question 3 - As an alternative approach, I've tried to get the bytes out of
the IPersistStream another way, with a view to storing this byte array
separately in the Session object. A first attempt is

   IPersistStream p = m_AAAClass.RCWClass as IPersistStream;

   if ( p != null )
   {
       System.IO.MemoryStream memstream = new System.IO.MemoryStream();
       ComStream cstream = new ComStream(memstream);
       if ( p != null )
       {
           p.Save( cstream, false );
           System.IO.MemoryStream mem = cstream.stream as
System.IO.MemoryStream;
           return mem.GetBuffer();
       }
       else
           return null;
   }
   return null;

This time the pointer to IPersistStream is null the first time, but after
that always throws a COMException with the message "The server threw an
exception". Am I barking up the wrong tree?

Fundamentally wanting to store an RCW class in the Session object doesn't
seem to be a strange thing to want to do, but after Googling myself into a
frenzy, it seems that very few people have asked about it. Those that have
have been told to set the sesseion state to InProc, but this isn't really an
option, as this means you can't run on a web farm. Any ideas please?

Cheers,

Chris
ben@pingware.com - 31 Jan 2005 21:58 GMT
Hi Chris,
Are you the same Chris Puncher who did
Snippet995?
If not, please accept my apologies...
== Ben Cohen

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.