Class containing the dictionary

public class Something { public Dictionary<string, string> Thing { get; set; } } 

does not serialize, throwing an exception at the time of creating an instance of the XmlSerializer class.

 XmlSerializer serializer = new XmlSerializer(typeof(Something)); 

How to bypass this restriction?

    2 answers 2

    As it turned out the built-in dictionary does not serialize. Or you need to write the serialization code yourself, implementing the IXmlSerializable interface . Or refuse the dictionary, which I did.

     public class Something { public List<KeyValuePair<string, string>> Thing { get; set; } } 

    Add items as

     thing.Add(new KeyValuePair<string, string>(key, value)); 

    Delete as

     thing.Remove(thing.First(item => item.Key.Equals(key))); 

      It has long been no longer engaged in serialization, too, was the same problem. Wash should be ref or out before typeof, if memory does not change me.