Serializing a list of Key/Value pairs to XML

KeyValuePair is not serializable, because it has read-only properties. Here is more information(thanks to Thomas Levesque).
For changing the generated name use the [XmlType] attribute.

Define your own like this:

[Serializable]
[XmlType(TypeName="WhateverNameYouLike")]
public struct KeyValuePair<K, V>
{
  public K Key 
  { get; set; }

  public V Value 
  { get; set; }
}

Leave a Comment