XmlSerializer - 有一个错误反映类型 [英] XmlSerializer - There was an error reflecting type

查看:17
本文介绍了XmlSerializer - 有一个错误反映类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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));

我收到一条异常消息:

有一个错误反映类型.

在数据类中有另一个复合对象.这是否也需要具有 [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] 属性.

You can exclude fields/properties from xml serialization by decorating them with the [XmlIgnore] attribute.

XmlSerializer 不使用 [Serializable] 属性,所以我怀疑这是问题所在.

XmlSerializer does not use the [Serializable] attribute, so I doubt that is the problem.

这篇关于XmlSerializer - 有一个错误反映类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆