反序列化对象时,DataContractSerializer返回null [英] DataContractSerializer returns null when deserializing an object

查看:110
本文介绍了反序列化对象时,DataContractSerializer返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi all!

I'm working with WCF and the DataContractSerializer to serializer a somewhat 
deep tree of entities (less than 10 levels). I'm using the PreserveReferences 
option as I've got entities that have a circular reference.

The application has been out for about 2 months, and it's been working just 
fine. Two days ago, however, when deserializing a received entity tree, I've 
started getting a SerializationException with the text : "Deserialized object 
with reference id xxx not found in stream".

I've traced it, and found that it is caused by entities in the XML stream, 
that due to the PreserveReferences option, are not serialized as themselves, 
but only refer to one instance to that entity somewhere else in the stream. 
That one instance comes up null when deserializing, when it really shouldn't, 
as I can see that it has all the values it needs. It's also a very simple 
entity, just a few fields and properties.

This has been happening in only that entity tree (I've got others that work 
just fine), and it's only been happening in XML received from 4 computers out 
of about 100 in the field.

If I remove the refering entities, and replace them with the direct fields 
and properties of the one instance entity, then everything works just fine.

How can I debug or somehow attach to DataContractSerializer, and find out 
why it returns null ? Or maybe tell DataContractSerizalizer to not store a 
reference to those entities ,and just serialize them as they are ?

推荐答案

您可以共享DataContract定义和失败实体的一些示例吗?

就调试到DataContractSerializer而言,现在可以在http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now- available.aspx .不幸的是,它还不包括WCF,但是正在开发中.

As far as debugging into the DataContractSerializer, a lot of the .NET framework source is now available for debugging at http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx. Unfortunately, it doesn't yet include WCF, but that's being worked on.


这篇关于反序列化对象时,DataContractSerializer返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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