Dictionary not deserializing

Posted by Shadow on Stack Overflow See other posts from Stack Overflow or by Shadow
Published on 2009-12-01T17:08:21Z Indexed on 2010/04/08 22:03 UTC
Read the original article Hit count: 145

Filed under:
|
|

I'm having a problem where one Dictionary in my project is either not serializing or not deserializing. After deserializing, the data I serialized is simply not in the object.

Here's the relevant snip of the class being serialized:

class Person : ISerializable {
    private Dictionary<Relation,List<int>> Relationships = new Dictionary<Relation,List<int>>();

    public Person(SerializationInfo info, StreamingContext context) {
        this.Relationships = (Dictionary<Relation, List<int>>) info.GetValue("Relationships", typeof(Dictionary<Relation, List<int>>));
        }

    public void GetObjectData(SerializationInfo info, StreamingContext context) {
        info.AddValue("Relationships", this.Relationships);
        }
    }

Note, this is binary serialization. Everything else in the project serializes and deserialzes correctly.

© Stack Overflow or respective owner

Related posts about c#

Related posts about serialization