How can I serialize an object with a Dictionary property?

前端 未结 7 531
故里飘歌
故里飘歌 2021-01-04 08:04

In the example code below, I get this error:

Element TestSerializeDictionary123.Customer.CustomProperties vom Typ System.Collec

7条回答
  •  时光说笑
    2021-01-04 09:05

    In our application we ended up using:

    DataContractSerializer xs = new DataContractSerializer(typeof (T));
    

    instead of:

    XmlSerializer xs = new XmlSerializer(typeof (T));
    

    which solved the problem as DatacontractSerializer supports Dictionary.

    Another solution is ths XML Serializable Generic Dictionary workaround also works in the above example, and there is a long discussion at that link from people using it, might be useful for people working with this issue.

提交回复
热议问题