This question is sort of a follow on from SerializationException when serializing lots of objects in .NET.
Situation: I have a network of nodes that are all interconnected and may have somewhere between 10-30 variables and/or references per node. The network is about 9 million entries, but I have cropped out a section of 11,000 entries and cut off the references that point to the rest of the network.
I'm trying to write this section of the network to disk but I'm getting the following error:
System.Runtime.Serialization.SerializationException
"The internal array cannot expand to greater than Int32.MaxValue elements."
NOTE: As pointed out by stuartd the limit to the number of items that can be serialized is 6 million.
The most likely reason for this is that there is still a connection to the rest of the network that I'm not aware of, however I have searched the code in great detail attempting to find where a potential connection might remain, but without any luck (I am going to keep looking so this may still be the cause, but I wanted to also explore other avenues).
Question: What pitfalls/easy to do mistakes are there with BinaryFormatter that I might be encountering? And what can I do to overcome this size limit?
Edit: Added the serialization code. "this" is my network object that contains the 11,000 nodes.
Stream testFileStream = File.Create(filename);
BinaryFormatter serilizer = new BinaryFormatter();
serilizer.Serialize(testFileStream, this);
testFileStream.Close();