XmlSerializer不能序列化Dictionary对象。。。

     异常:System.NotSupportedException : Cannot serialize member corp.Azure.DictProperties of type System.Collections.Hashtable, because it implements IDictionary.

    原来是因为Dictionary类型只实现的ISerializable接口,而没有实现IXmlSerializable接口,所以在.net 3.0以前用XmlSerializer是不能序列化的。在.net 3.0及以后版本可以使用DataContractSerializer进行序列化。

    一老外的详细解释:
   This question has come up a few times on internal discussion threads recently so I wanted to summarize some highlights. It's correct that you get this error because Dictionary isn't IXmlSerializable. The reason it's this way is layering concerns: Dictionary is in mscorlib.dll but IXmlSerializable is in System.Xml.dll, and we couldn't take a dependency in that direction.
   Before .NET 3.0 you'd have to grow your own solution, such as subclassing Dictionary to implement IXmlSerializable. Moving forward, the recommended solution is to use System.Runtime.Serialization.DataContractSerializer. Note that this is part of the Windows Communication Foundation (WCF), in .NET 3.0. For more details on what is serializable using the data contract serializer, see: http://msdn2.microsoft.com/en-us/library/ms731923.aspx

   --the end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值