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
  • 相关阅读:
    harbor无法登陆解决
    k8s中使用harbor
    harbor扩容
    harbor设置开机自启
    设置开机自启
    关Java的内存模型(JMM)
    多线程相关概念
    多线程(JDK1.5的新特性互斥锁)
    synchronized关键字
    【异常】redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'PSETEX'
  • 原文地址:https://www.cnblogs.com/fuhongwei041/p/1555692.html
Copyright © 2011-2022 走看看