Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

Off Proc Session State and Custom Classes

If you want to store a custom class in an off-proc session (SQL Server, ASP.NET State Service, custom) that serializes objects, you must be aware that if the base class for your custom class implements, directly or indirectly, System.Runtime.Serialization.ISerializable, you must add a public or protected constructor to your class that has the following signature:

public MyClass(SerializationInfo info, StreamingContext context): base(info, context)

{

}

As you can see, you just have to call the base class' constructor that receives the same parameters. This is because in .NET an interface cannot specify constructors, but, in the case of ISerializable, the constructor is also a requirement, not just method GetObjectData.

Posted: May 26 2009, 09:53 AM by Ricardo Peres | with 5 comment(s)
Filed under: ,

Comments

Igor said:

Actually it is true for any custom serialization scenario. Not only "store a custom class in an off-proc session".

# May 26, 2009 9:11 AM

Igor said:

Oops, sorry, i didn't get your point.

Don't pay your attention to my previous comment.

# May 26, 2009 9:19 AM

medical transcription said:

hmmm...hard to understand...can anyone explain why a public must to be added?

# June 30, 2009 5:43 PM

Ricardo Peres said:

medical,

That's just the way the BinaryFormatter class works: if the serializable class implements ISerializable, it tries to use its methods and a special constructor.

# June 30, 2009 7:08 PM

medical transcription said:

Ah, thanks. I understand much better now.

# October 9, 2009 8:43 PM