All,
Environment: ASP.net 2.0, Nhibernate 3.3, Json.net (latest, 6.x)
I am using latest version of Newtonsoft.Json library. When I load an entity using nhibernate (my entities reference other entities and are loaded lazily) I receive either an out of memory exception or stackoverflow exception.
Code for outofmemory exception:
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
string json = JsonConvert.SerializeObject(container.DataItem, settings);
Code for stackoverflow exception:
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
string json = JsonConvert.SerializeObject(container.DataItem, settings);
People have these issues but there seems to be no solution. I see responses such a your graph is to large or too deep but my object graph is small,- I just call the code above lots of times (once per each object). I need a fix for this.