Solving Binary serialization versioning conflicts - The HashTable problem
Attached is the VersionSupportingBinaryFormatter, with a bug fix of a problem that was raised in your blog regarding deserialization of hashtables with the VersionSupportingBinarySerializer.
The problem was that the hashtable class implements the OnDeserialization method (defined in IDeserializationCallback),
if (buckets!=null)
{
return; //Somebody had a dependency on this hashtable and fixed us up before the ObjectManager got to it.
}
if (m_siInfo==null)
{
throw new SerializationException(Environment.GetResourceString("Serialization_InvalidOnDeser"));
}
the first lines of code in the hashtable.cs OnDeserialize are:
The m_siInfo is being assigned when the SerializationInfo (ISerializable) constructor is called.
When I register the surrogate I run over that call, which made me think it is stupid to do it any how, due to the fact that custom serialization behaviors will not be reproduce when my reflection surrogate is called, so I do not register any more the VersionSupportingSerializationSurrogate for classes that implements the ISerializable interface.
Cheers,
Jonathan Einav
Software Project Manager"