0

I'm getting this "Could not evaluate expression" serialization output when I try to serialize a big list. Is there any way to prevent this behaviour?

The worst part is that there is no common exception thrown. If the list is too big, instead of getting an exception to warn me, I just get the mentioned expression instead of my wanted json formatted list.

Note: in case it helps, I'm running my tests with a simple poco entity that looks like this:

public class SomeEntity
{
    public int Id {get;set;}
    public string Name {get;set;}
    public DateTime SomeDate {get;set;}
    public bool IsTrue {get;set;}
    public short SomeNumber {get;set;}
}

And the lines of code that fail are like this:

var list = new List<SomeEntity>();
LoadHugeAmmountsOfItemsIntoList(list);  // this gets me several thousands of items into the list
var serializedList = JsonConvert.SerializeObject(list); // The error appears when I have somewhere between 125k and 150k items or more in the list
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • I couldn't reproduce this with 1 million items, I got an OutOfMemoryException at 3 million items. (even though I had plenty of physical memory left) – parachutingturtle Aug 29 '14 at 09:13
  • 1
    Someone pointed out to me that this was an issue related to Visual Studio, (I can't remember the name of the user, the answer he/she gave somehow was lost from SO before I could mark it as accepted) but this link was given as part of the answer: http://weblog.west-wind.com/posts/2013/Nov/21/Visual-Studio-2013-Could-not-evaluate-Expression-Debugger-Abnormality Anyway, in the end, this problem is not related to the json.net library. – Enlacumbre Aug 29 '14 at 09:38
  • @parachutingturtle I have not tested to the point of getting an OutOfMemoryException since the error showed before that point. But in my tests I realized that even though this error did not happen (in my case it appears between 125k and 150k items), I still have to use a list below 38k or I cannot use it as a parameter for a post webapi service. – Enlacumbre Aug 29 '14 at 09:44

0 Answers0