0

I am having a problem I've got a big class, in that class Ive 4 properties that contains other class, ant that class contain various lists and models(simple class with properties)

Class looks like:

[Serializable]
public class BackupProject 
{
    public DocumentSet Documents;
    public CompareSet MetaData;
    public RelationshipSet Relationships;
    public Dictionary<string, ItemConfig> DocumentData;
}

To serialize I'm using :

using (FileStream stream = File.Open(fullPath + "/" + backupFile, FileMode.Create))
{
     stream.Position= 0;
     var bformatter = new BinaryFormatter();
     using (ZipOutputStream zipStream = new ZipOutputStream(stream))
     {
           zipStream.SetLevel(9);
           ZipEntry zipEntry = new ZipEntry("BackupProject") {DateTime = DateTime.Now};
           zipStream.PutNextEntry(zipEntry);
           bformatter.Serialize(zipStream, documents);
     }
}

As you see I tried data compression and still I am getting:

System.Runtime.Serialization.SerializationException "The internal array cannot expand to greater than Int32.MaxValue elements."

That's why I need to chunk up this class, But have no idea how to do it witch such irregular class content.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Wojciech Szabowicz
  • 3,646
  • 5
  • 43
  • 87
  • In what line does this exception happen? – Maor Veitsman Oct 16 '15 at 07:55
  • 1
    bformatter.Serialize(zipStream, documents); in this line – Wojciech Szabowicz Oct 16 '15 at 08:06
  • maybe you can Serialize your class as XML and then convert it to Binary,depending on what you are doing wit your serialized class – WiiMaxx Oct 16 '15 at 08:06
  • Perhaps this would be useful for you: http://stackoverflow.com/questions/569127/serializationexception-when-serializing-lots-of-objects-in-net – Maor Veitsman Oct 16 '15 at 08:10
  • Hmm, maybe but I need a little bit of explanation to that code, never used that :) – Wojciech Szabowicz Oct 16 '15 at 09:24
  • We can't answer that question without seeing your contained types including `DocumentSet`, `CompareSet`, `Relationships` and `ItemConfig`. Can you share them? Most importantly, *which of them contain references to other objects in the graph*? But you could start with http://mikehadlow.blogspot.com/2007/07/serializing-lots-of-different-objects.html – dbc Dec 19 '16 at 22:21

0 Answers0