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:
Sy
Binary serilization of very large objects
If you run into this limitation binaryformatter the internal array cannot expand to greater than int32.maxvalue elements using BinaryFormater, help yourself with this code snippet
Step 1
Install nuget package: Install-Package Newtonsoft.Json.Bson -Version 1.0.2
using Newtonsoft.Json.Bson; //import require namesapace
//Code snippet for serialization/deserialization
public byte[] Serialize(T obj)
{
using (var memoryStream = new MemoryStream())
{
using (var writer = new BsonDataWriter(memoryStream))
{
var serializer = new JsonSerializer();
serializer.Serialize(writer, obj);
}
return memoryStream.ToArray();
}
}
public T Deserialize(byte[] data)
{
using (var memoryStream = new MemoryStream(data))
{
using (var reader = new BsonDataReader(memoryStream))
{
var serializer = new JsonSerializer();
return serializer.Deserialize(reader);
}
}
}