ashutosh raina ashutosh raina - 1 year ago 80
C# Question

Getting an OutOfMemoryException while serialising to JSON?

I am serializing , a

MultiDictionary<String,Object> to json .

It has 618 elements with elements being deeply nested ,i.e. a single Object may have several dictionary like objects in it . I am using JSON.Net

String json = JsonConvert.SerializeObject(json, Newtonsoft.Json.Formatting.Indented);

what am i missing ?

This was working fine till i was using dynamic , i had to switch to MultiDictionary to allow multiple properties of the same name . It works for most cases , only when the number of items is large , it breaks .


I have been able to get a hold of the Memory consumption but cutting down on some elements that were getting added recursively to each element.

Answer Source

It appears that you're running into Ciruclar Reference that is causing OutOfMemoryException or your objects are simply too large for your memory. Use NDepend to check this.

You might find useful getting the total size of your objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download