How can I serialize an object with a Dictionary property?

前端 未结 7 534
故里飘歌
故里飘歌 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.

    0 讨论(0)
提交回复
热议问题