Deserialization Problems

While prototyping something today, I had an object that I wanted to be able to serialize out to disk. This object was derived from Hashtable, which already implemented the ISerializable interface so I thought I was all set. Serialization worked fine. Then I went to deserialize it and I got the following error:

The constructor to deserialize an object of type ... was not found

I was slightly confused until I looked at the documentation for the Hashtable's constructor. The constructor for deserializing was protected. I needed to make a public constructor and call the base class' constructor:

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

7 Comments

Comments have been disabled for this content.