请教使用XmlSerializer序列化对象时的一个异常错误

wbcnxa 2003-08-30 04:50:47
我定义了一个类,类中有个属性是ArrayList类型。现在声明此类的一个实例化对象,向ArrayList类型的属性添加一个元素,添加的元素是一个数组。
问题出现了,当序列化这个对象时就会出现异常。

究竟为什么!
...全文
54 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wbcnxa 2003-08-31
  • 打赏
  • 举报
回复
谢谢楼上热心的哥们儿!

不过我的问题不是绕过这个属性不序列化,这个属性是必须要序列化的,因此不能使用[XmlIgnore]。

不过这个问题已经解决,详见我发的另一篇请教该问题的帖子,高手作了完美解释!
雪狼1234567 2003-08-30
  • 打赏
  • 举报
回复
而且这儿几个关于序列化的讲得不错
重写序列化
ms-help://MS.VSCC/MS.MSDNVS.2052/cpguide/html/cpconoverridingserializationofclasseswithxmlattributeoverridesclass.htm

使用属性控制 XML 序列化
ms-help://MS.VSCC/MS.MSDNVS.2052/cpguide/html/cpconcontrollingserializationbyxmlserializerwithattributes.htm

雪狼1234567 2003-08-30
  • 打赏
  • 举报
回复
看如下:
增加 XmlIgnoreAttribute attribute:

[XmlIgnore]
public string Comment;

or you can override it when you call the serializaiton routine, check the code sample for XmlAttributes.XmlIgnore property:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlserializationxmlattributesclassxmlignoretopic.asp

110,531

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧