0

I want to ignore all elements of Dictionary while serializing as those members cause an exception

example class:

public class TestClass{
    public string StringTest { get; set; }
    public int IntTest { get; set; }
    public Dictionary<int, string> someDictionary { get; set; }
}

What i tried(unsuccessfull)

XmlAttributeOverrides xOver = new XmlAttributeOverrides();

XmlAttributes attrs = new XmlAttributes();
attrs.XmlIgnore = true;

xOver.Add(typeof(Dictionary<int, string>), attrs);

XmlSerializer serialiser = new XmlSerializer(objectToConvert.GetType(), xOver);
serialiser.Serialize(writer, objectToConvert);
MichaelD
  • 8,377
  • 10
  • 42
  • 47
  • possible duplicate of [Why isn't there an XML-serializable dictionary in .NET?](http://stackoverflow.com/questions/1124597/why-isnt-there-an-xml-serializable-dictionary-in-net) – Hans Passant Sep 15 '10 at 15:31

1 Answers1

0

Have you tried it like this instead.

[XmlIgnore]
public Dictionary<int.string> someDictionary{get;set;}
ywm
  • 1
  • 1