Why can't a Dictionary<key,value> be serialized? Or can it?
I think this is just a limitation of Microsoft's XML serializer (System.Xml.Serialization.XmlSerializer
). Most other serializers will support dictionaries.
This is not a general limitation of serialization, not even xml serialization, just a limitation of that implementation. XmlSerializer
is pretty weak in general.
Charlie Kou
Updated on June 04, 2022Comments
-
Charlie Kou almost 2 years
(Havent spotted a question asking this).
Why cant a Dictionary be serialized?
Most resources, websites, blogs etc say that it cannot be serialized. However reading "CLR via C#" 3rd edition, page 664 gives Dictionary as an example of an object graph which can be serialized.
Note that this chapter talks about Binary Serialization. So is it that it can be serialized using the BinaryFormatter but it cannot be XML serialized?
Or is there some difference here that Im missing between an IDictionary and a Dictionary?
To clarify... under what circumstances can a Dictionary be serialized and under what circumstances can it not be serialized.
Thanks.
-
Charlie Kou over 12 yearsOk, interesting - any ideas why the limitation is in place?