gpt4 book ai didi

c# - 为什么我不能使用 DataContractSerializer 序列化一个对象?

转载 作者:行者123 更新时间:2023-11-30 15:12:44 25 4
gpt4 key购买 nike

我正在尝试使用 DataContractSerializer 序列化一个类型,但出现以下异常。这不是针对 SOA 服务的,但如果可能的话,我仍然希望使用 DataContractSerializer。我正在使用 .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.

最佳答案

你能发布你的类定义吗?

您似乎正在尝试序列化一个具有委托(delegate)类型字段的类,我很确定这会使序列化程序阻塞。

您是否使用 DataContract/DataMember 属性装饰了您的类?在 3.5 SP1 中,序列化程序有一个默认行为,如果类中没有标记这些属性,则默认情况下会序列化类中的所有公共(public)内容。也许您应该明确标记每个需要使用 DataMember 属性序列化的属性,并忽略那些不应该序列化的属性。

除此之外,我们还需要查看您的类定义以获得更多帮助。

关于c# - 为什么我不能使用 DataContractSerializer 序列化一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/822082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com