Follow @RoyOsherove on Twitter

Solving Binary serialization versioning conflicts - The HashTable problem

A while ago I posted about a solution to Binary Serialization version conflicts, via Jonathan Einav. A comment was posted on that blog post regarding a problem to which Jonathan is replying through me via email, and for which you can download the latest version of the fixed class:
The problem exists when trying to serialize a HashTable, and Jonathan provides a fix here.

 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.


Jonathan                  Einav

Software  Project  Manager"

Defensive event publishing, a different approach

What Algorithms should you test and how?