Dictionary<> serialization
Posted: Tue Jun 27, 2017 5:50 am
Is the Dictionary supposed to be able to serialize? I don't see it listed as not being supported on XmlSerializer Limitations:
[DataContract]
public class IPCGlobalConfiguration
{
[DataMember]
public Dictionary<int, string> StandbyServers { get; set; }
.....
I get an error:
Exception thrown: 'System.InvalidOperationException' in System.Xml.dll:
"Cannot serialize member SharedObjects.IPCGlobalConfiguration.StandbyServers of type System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary."
[DataContract]
public class IPCGlobalConfiguration
{
[DataMember]
public Dictionary<int, string> StandbyServers { get; set; }
.....
I get an error:
Exception thrown: 'System.InvalidOperationException' in System.Xml.dll:
"Cannot serialize member SharedObjects.IPCGlobalConfiguration.StandbyServers of type System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary."