数据合同序列化错误

编程入门 行业动态 更新时间:2024-10-28 10:33:31
本文介绍了数据合同序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是 如何在所有类成员上设置[DataMember]

所以我必须使用字典和其他成员序列化一个类.

So I have to serialize a class with dictionaries and other members.

我选择了本身的数据上下文序列化

I have chonse the datacontext serialization that se

public SimpleDataGridSample() { if (false) { MyClass theclass = new MyClass(); var serializer = new DataContractSerializer(typeof(MyClass)); using (Stream fileStream = File.Open("aaa.bin", FileMode.Create)) { XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(fileStream); serializer.WriteObject(binaryDictionaryWriter, theclass); binaryDictionaryWriter.Flush(); } } else { MyClass theclass; var serializer = new DataContractSerializer(typeof(MyClass)); using (Stream fileStream = File.Open("aaa.bin", FileMode.Open)) { XmlDictionaryReaderQuotas xq = new XmlDictionaryReaderQuotas(); XmlDictionaryReader binaryDictionarReader = XmlDictionaryReader.CreateBinaryReader(fileStream, xq); theclass = (MyClass)serializer.ReadObject(binaryDictionarReader); } } } }

那行得通.

但这只是一个测试程序. 在申请更复杂的课程时,出现此错误:

But that was just a test program. When applying to my class which is more complicated I get this error:

{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}

不明白索引在说什么.

主类由服务器成员(也包括字典和可观察列表)和其他子类组成. 每个班级都标记为[DataContract(IsReference = true)] 并且每个成员都标记为[DataContext]

The main class is made of serveral members (also dictionaries and observable lists) and other sub classes. Every class is marked [DataContract(IsReference = true)] and every member is marked [DataContext]

感谢

推荐答案

其他用户无法进行查询的确定.最初,我不知道问题出在哪里,因为我以前从未使用过DataContract序列化,而且对此还不熟.但这有效! 使我步入正轨的是古老的智能感知能力. 这是创建后的变量,它包含异常. 一样谢谢你

OK that was IMPOSSIBLE for other users to aswer. At first I didn't understand where the problem was because I never used used DataContract serialization before and was not proficent about it. But it works! What put me on track was the good old intellisense. This is the variable after having been created and it contains the exception. Thank you the same

更多推荐

数据合同序列化错误

本文发布于:2023-10-25 14:36:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   合同   序列化   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!