-1

I created my own Custom Serialization method with JSON.NET, the method looks like :

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
    var Obj = (xObject)value;
    writer.WriteStartArray();

    foreach(var TargetObject in Obj)                        
    {
       writer.WriteStartObject();
       writer.WritePropertyName(TargetObject.Data.Key);
       writer.WriteValue(TargetObject.Data.Value);
       writer.WriteEndObject();         
    } 
    writer.WriteEndArray();        
}

I got an OutOfMemoryException exception at writer.WriteValue(TargetObject.Data.Value), saying insufficient memory, any idea that I can keep my custom serialization but avoid this issue?

Note, yes, you are right,the object I'm trying to serialize is more than 1GB.

dbc
  • 104,963
  • 20
  • 228
  • 340
Kevin Simple
  • 1,225
  • 10
  • 22

2 Answers2

0

Try using streaming and PushStreamContent as per this blog.

You may have to abandon the JsonWriter and do more manual serialisation using an unbuffered stream.

kristianp
  • 5,496
  • 37
  • 56
  • not quite, what i found is the internal exception overflow on String Type...its just too big, the built in String cant handle... – Kevin Simple Nov 04 '16 at 04:39
0

I found finally, the reason is because the exception from overflowing the String type from .NET. So , simply, its just too big data for a String field, there is no solution as there isn't a problem with json.net, my solution is to simplifying my data, or output as a file on drive rather than storing its whole data any time in memory as string field, just impossible....

Kevin Simple
  • 1,225
  • 10
  • 22