As the exception (InvalidOperationException
with an inner UnsupportedException
) says you can't simply deserialize it into a Dictionary
.
Here is one way to overcome of this difficulty:
Define KeyValue
[Serializable]
public struct KeyValue
{
public string Key { get; set; }
public bool Value { get; set; }
}
As an alternative you might take advantage of the built-in KeyValuePair<TKey, TValue>
Use XmlArray
and XmlArrayItem
[XmlArray("SeriesLocationMap")]
[XmlArrayItem("KeyValueOfstringboolean")]
public List<KeyValue> IntermediateContainer { get; set; }
Use XmlIgnore
to convert List to Dictionary<string, bool>
[XmlIgnore]
public Dictionary<string, bool> SeriesLocationMap => IntermediateContainer.ToDictionary(x => x.Key, y => y.Value);
I've tested it without namespaces, so you need to specify them at the right place to be able to read them properly.
Alternatively you might give it a try and use DataContractSerializer
which does support Dictionary.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…