Datacontract serialization error


This is the continuation of <a href="https://stackoverflow.com/questions/34391288/how-to-set-datamember-on-all-class-members?noredirect=1#comment56526541_34391288" rel="nofollow">How to set [DataMember] on all class members</a>

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); } } } }

and that worked.

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"}

Can't understand what index is talking about.

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]



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

<a href="https://i.stack.imgur.com/73iMk.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/73iMk.png" data-original="https://i.stack.imgur.com/73iMk.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>


  • Attempting to use OOPFactory to parse 271 benefits using EligibilityBenefitDocument
  • Get rid of root element when serializing array
  • How to cancel and delete the uploading file in asp.net mvc 3?
  • How to add paragraph wise texts separated by vertical line into itextsharp created PDF
  • Cannot open include file: 'cpprest/http_client.h'
  • How to avoid OutOfMemoryException while loading large chunks of data from a database?
  • Github ERROR: Repository not found (yes, another one)
  • How to execute a shell script through python
  • The process cannot access the file because it is being used by another process
  • MongoDB: How to Sort a Query Before Updating
  • QT: set stylesheet for a QMenu object
  • how do disable disk cache in c# invoke win32 CreateFile api with FILE_FLAG_NO_BUFFERING
  • Get row for each user where the count of a value in a column is maximum
  • Uploading file with WCF streaming, tiny reads from stream
  • Error: Type parameter 'T' cannot be inferred
  • How to write string.Contains(someText) in expression Tree
  • DependencyObject.AssociatedObject is always null
  • when does setTimeout start executing in a inline
  • how to set to NULL all the filestream varbinary(max) fields?
  • Unzip archive in .Net CORE 1.0
  • Streaming screenshots over WebRTC as a video stream from iOS
  • How do I register classes by both interface and namespace with Windsor?
  • nodemcu custom firmware build problems
  • Android Studio Can't Find tools.jar
  • Convert SQLite database to XML
  • Eclipse CDT error: Unable to compile
  • Play WS (2.2.1): post/put large request
  • Bad request using file_get_contents for PUT request in PHP
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Comma separated Values
  • Load html files in TinyMce
  • Error creating VM instance in Google Compute Engine
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • how does django model after text[] in postgresql [duplicate]
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster