Serialization is one of the concepts, that is always intriguing to developers.

One of my coworker, was trying to move the in process session state management into an out of proc session state service. We were getting some exceptions during the transition, of course when objects need to be persisted in a session, they have to serializable and more than that, if it is an aggregated object (object which may have multiple objects encapsulated in it) then a null check should be performed on each object in the serialization / deserialization method definitions.  

 

VB.NET

 

Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
 
  If Not IsNothing(_empobject) Then 
        info.AddValue("_empobject", _empobject.Serialize(_empobject)) 
 End If 
 
End sub
 
 Private Sub New(ByVal Info As SerializationInfo, ByVal Context As StreamingContext)
 
      If Not String.IsNullOrEmpty(Info.GetString("_empobject")) Then 
   _empobject = New EmpObject().DeSerialize(Info.GetString("_empobject")) 
     End If 
 
 End Sub

C#

public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)

{    

    if ((_empobject != null)) {

        info.AddValue("_empobject", _empobject.Serialize(_empobject));

    }

   }

private New(SerializationInfo Info, StreamingContext Context)

{  

    if (!string.IsNullOrEmpty(Info.GetString("_empobject"))) {

        _empobject = EmpObject().DeSerialize(Info.GetString("_empobject"));

    }  

}

Finally, how do you serialize a generic list ( of any Type). I was thinking about that, and found this article which explains clearly  how to do it.

http://www.eggheadcafe.com/software/aspnet/30067316/how-can-i-add-generic-lis.aspx

If you wonder how to xml serialize a generic list, look at the below blog post

http://www.hanselman.com/blog/XmlSerializingAGenericListltgt.aspx

If you want a tool to convert a code from VB to C# , you could use the below link to do that

http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx

 

posted on Monday, December 10, 2007 10:06 PM | Filed Under [ .NET Framework ]

Comments

Gravatar
# re: Serialization Tips
Posted by awd
on 12/5/2010 3:36 AM
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
Gravatar
# Houston Home Security
on 12/6/2011 6:59 PM
I want to show my admiration of your writing skill and ability to make audience, browse the whole thing to the end. I'd really like to read more of your blogs and to talk about my views with you. I'll be your frequent website visitor, that’s for sure.
Gravatar
# re: Serialization Tips
Posted by Garcia35Rose
on 3/23/2012 3:40 AM
The personal loans are useful for people, which would like to organize their organization. By the way, it is very easy to get a small business loan.
Gravatar
# re: Serialization Tips
Posted by BlairCHERYL35
on 4/14/2012 7:55 AM
I argue that experienced specialists who work at help writing paper firm are able to see a right way from any complicated position. Moreover, guys must respect their contribution because they work hard to fulfill our academic requirements!
Gravatar
# re: Serialization Tips
on 4/23/2012 1:45 PM
You just can't find any such thing as a free reverse phone lookup. Believe me, I've looked! But the good news is that you can find out everything you want to know about a cell phone user by simply paying a small sum of money for an extensively detailed report ... you know?
Post Comment
Title *
Name *
Email
Url
Comment *
Please add 8 and 5 and type the answer here: