Welcome to RightHand's community place Sign in | | Help

How to deserialize a Dictionary<TKey, TValue> descendant using binary formatter

I just run across the problem of how to deserialize a Dictionary<TKey, TValue> descendant using BinaryFormatter. Serialization is not a problem, just mark the derived class with [Serializable] attribute and there you go. However, when you try deserializing it an exception is rised saying that there is no appropriate constructor for Dictionary<TKey, TValue> even if a parameterless constructor exists (which is usually enough). The trick is that you have to implement a constructor with (SerializationInfo si, StreamingContext sc) parameters (in simple case it has just to call base class' constructor). The reason for this is, that Dictionary class uses custom serialization via ISerializable interface.
Published 6. avgust 2005 23:48 by Miha Markic
Filed under:

Comments

# Deserializing a Dictionary Object &laquo; Brent Challis&#8217; Weblog

Anonymous comments are disabled