zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    实验三 面向对象分析与设计
    实验二 结构化分析与设计
    软件开发文档与工具的安装与使用
    ATM管理系统
    活动图与流程图
    四则运算
    实验四 决策树算法及应用
    实验三 朴素贝叶斯算法及应用
    实验二 K-近邻算法及应用
    实验一 感知器及其应用
  • 原文地址:https://www.cnblogs.com/fuhongwei041/p/1555692.html
Copyright © 2011-2022 走看看