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.



Comments have been disabled for this content.