Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializationException when serializing lots of objects in .NET
    text
    copied!<p>I'm running into problems serializing lots of objects in .NET. The object graph is pretty big with some of the new data sets being used, so I'm getting:</p> <pre><code>System.Runtime.Serialization.SerializationException "The internal array cannot expand to greater than Int32.MaxValue elements." </code></pre> <p>Has anyone else hit this limit? How have you solved it?</p> <p>It would be good if I can still use the built in serialization mechanism if possible, but it seems like have to just roll my own (and maintain backwards compatibility with the existing data files)</p> <p>The objects are all <a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object" rel="noreferrer">POCO</a> and are being serialized using <code>BinaryFormatter</code>. Each object being serialized implements <code>ISerializable</code> to selectively serialize its members (some of them are recalculated during loading).</p> <p>It looks like this an open issue for MS (<a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=303278" rel="noreferrer">details here</a>), but it's been resolved as Wont Fix. The details are (from the link):</p> <blockquote> <p>Binary serialization fails for object graphs with more than ~13.2 million objects. The attempt to do so causes an exception in ObjectIDGenerator.Rehash with a misleading error message referencing Int32.MaxValue.</p> <p>Upon examination of ObjectIDGenerator.cs in the SSCLI source code, it appears that larger object graphs could be handled by adding additional entries into the sizes array. See the following lines:</p> <pre><code>// Table of prime numbers to use as hash table sizes. Each entry is the // smallest prime number larger than twice the previous entry. private static readonly int[] sizes = {5, 11, 29, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853, 25717, 51437, 102877, 205759, 411527, 823117, 1646237, 3292489, 6584983}; </code></pre> <p>However, it would be nice if serialization worked for any reasonable size of the object graph.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload