使用的DataContractSerializer为什么我不能序列化一个对象? [英] Why can't I serialize an object using DataContractSerializer?

查看:299
本文介绍了使用的DataContractSerializer为什么我不能序列化一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用序列化的DataContractSerializer的一个类型,我得到下面的异常。这不是一个SOA服务,但我还是想尽可能使用DataContractSerializer的。我使用的.Net 3.5 SP1。




键入
'System.DelegateSerializationHolder + DelegateEntry'
数据合同名称
'DelegateSerializationHolder.DelegateEntry: http://schemas.datacontract.org/2004/07/不希望系统'
的。添加任何类型的不
静态已知已知
类型的列表 - 例如,通过使用
KnownTypeAttribute属性或由
将它们添加到已知类型$ B $列表b传递给DataContractSerializer的。



解决方案

您可以发表您的类定义?



好像你正试图序列化有类型的委托,我敢肯定会使串行噎死的领域类。



难道你装饰与DataContract /数据成员的类属性?在3.5 SP1存在用于串行,如果它不与这些属性标记默认序列化在一类一切公用默认行为。也许你应该明确地标记出需要与数据成员属性被序列化,并离开了那些不应该是每个属性。



除此之外,我们需要看到您的类定义更多的帮助。


I'm trying to serialize a type using the DataContractSerializer and am getting the exception below. This isn't for an SOA service, but I would still like to use the DataContractSerializer if possible. I am using .Net 3.5 SP1.

Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

解决方案

Can you post your class definition?

It seems like you are trying to serialize a class which has a field of type delegate, which I'm pretty sure will make the serializer choke on.

Did you decorate your class with the DataContract / DataMember attributes? In 3.5 SP1 there is a default behavior for the serializer that serializes everything public in a class by default if it is not marked with those attributes. Maybe you should explicitely mark each property that needs to be serialized with a DataMember attribute and leave out those that should not be.

Other than that, we would need to see your class definition for more help.

这篇关于使用的DataContractSerializer为什么我不能序列化一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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