There was an error reflecting type - XML Serialization issue

前端 未结 4 530
轮回少年
轮回少年 2020-12-31 20:00

I have a Dictionary object which needs to be written into an XML file. The dictionary contains String type as Key and a custom class\'s Object (Deriving from System.Windows.

4条回答
  •  别那么骄傲
    2020-12-31 20:25

    Generic dictionaries cannot be XmlSerialized. The error you get is caused by the public property DicCtrl.

    • Use the [XmlIgnore] attribute to skip this property when serializing (which is probably not what you want).
    • Change the type of the property to a type that can be serialized e.g. List
    • Find or implement a serializable dictionary
    • Or implement IXmlSerializable

    BTW the [Serializable] attribute is only needed for binary serialization. You do not need it for Xml serialization.

提交回复
热议问题