问题描述
使用C#.NET 2.0,我有确实有 [Serializable接口]
就可以了属性的复合数据类。我创建一个的XMLSerializer
类,并传递一个到构造函数:
Using C# .NET 2.0, I have a composite data class that does have the [Serializable]
attribute on it. I am creating an XMLSerializer
class and passing that into the constructor:
XmlSerializer serializer = new XmlSerializer(typeof(DataClass));
我得到一个异常的说法:
I am getting an exception saying:
有一个错误的反射式。
内部数据类有另一个复合对象。这是否也需要有 [Serializable接口]
属性,或者按首要对象上有它,它递归地将其应用到里面的所有对象?
Inside the data class there is another composite object. Does this also need to have the [Serializable]
attribute, or by having it on the top object, does it recursively apply it to all objects inside?
推荐答案
看看你得到的内部异常。它会告诉你,这是有问题的序列化哪个字段/属性。
Look at the inner exception that you are getting. It will tell you which field/property it is having trouble serializing.
您可以通过使用 [XmlIgnore]
属性装饰它们排除XML序列化字段/属性。
You can exclude fields/properties from xml serialization by decorating them with the [XmlIgnore]
attribute.
我不认为的XmlSerializer
使用 [Serializable接口]
属性,所以我怀疑这就是问题所在
I don't think that XmlSerializer
uses the [Serializable]
attribute, so I doubt that is the problem.
这篇关于XmlSerializer的 - 有一个错误的反射式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!