RuntimeType:HTTP://schemas.datacontract.org/2004/07/System'预计不会 [英] RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected
问题描述
好了,所以我得到的DataContractSerializer与我的对象图的工作。看到我前面的问题了解更多信息。
的 http://stackoverflow.com/questions/736568/serialization-derialization-of-a-tree-structure
的http://stackoverflow.com/questions/736900 /在解串器 - 有 - 无knowlege-OF-任意类型的-映射到这个合同
不过,我的一个域, _UserPropertyDefinitions ,定义如下图所示。它定义了该用户可以在数据结构添加到自定义对象属性的列表。该字符串是一个独特的键来标识属性,Type是属性的类型始终是一颗灵长类动物的类型像BOOL,INT,弦乐等等等等。
每个对象都有一个对应的词典(字符串键,对象的值)集合来存储它为任何用户属性
<值pre>
[数据成员]
私人字典<字符串类型> _UserPropertyDefinitions;
我的对象图连载罚款时,该属性是空集,但有一次我一个自定义属性添加到这个系列我在尝试用DataContractSerializer的序列化时,以下情况例外。
键入System.RuntimeType数据
合同名称
'RuntimeType: http://schemas.datacontract.org/2004/07/System '$预计不会b $ b的。添加任何类型的不
静态已知已知
类型的列表 - 例如,通过使用
KnownTypeAttribute属性或由
将它们添加到已知类型$ B $列表b传递给DataContractSerializer的。
块引用>
如果我删除的数据成员属性,这个领域我可以序列化/与出反序列化得到一个例外,但当然我失去我已经在这个领域创建的设置。
解决方案我敢肯定,
键入
不会序列化非常好 - 而且可能不会在数据合同属于无论如何,因为(具体是实现)它违背了一个数据合同的主要目标之一...
不过,我想到的最好的办法是换了一个
词典<字符串,字符串>
,使用键入
的AssemblyQualifiedName
或全名
。Ok so I got DataContractSerializer working with my object graph. See my previous questions for more information.
http://stackoverflow.com/questions/736568/serialization-derialization-of-a-tree-structure
However, one of my fields, _UserPropertyDefinitions, is defined as shown below.. It defines a list of custom properties that this user can add to objects in the data structure. The string is a unique key to identify the property, and Type is the type of the property which is always a primative type like Bool, Int, String etc etc..
Each object has a corresponding Dictionary(String key, Object value) collection to store the values it has set for any of the "User Properties"
[DataMember] private Dictionary<string, Type> _UserPropertyDefinitions;
My object graph serializes fine when this property is an empty collection, yet once I add a custom property to this collection I get the following exception when trying to serialize with DataContractSerializer.
Type 'System.RuntimeType' with data contract name 'RuntimeType: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.
If I remove the DataMember attribute for this field the I can serialize/deserialize with out getting an exception, but of course I loose the settings I've created in this field.
解决方案I'm pretty sure that
Type
isn't going to serialize very well - and arguably it doesn't belong in a data-contract anyway, since (being implementation specific) it defeats one of the main aims of a data-contract...However, I expect the best approach would be to swap that for a
Dictionary<string,string>
, using theType
'sAssemblyQualifiedName
orFullName
.这篇关于RuntimeType:HTTP://schemas.datacontract.org/2004/07/System'预计不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!