If you get the InvalidOperationException:
when trying to serialize data to JSON representation, then most likely you are doing something wrong. AJAX is not meant to move large amounts of data – rethink your application!
However, sometimes the limit is too low – in my case, a web service test application for the client, so they could test their own web services before claiming they are ready. One of the services gives quite a lot of data – and the test app needed to show the data as XML as well, so the actual JSON size was 26MB (as a sidenote, both Chrome and Firefox 4 crashed while parsing the data – surprisingly, IE9 was the only browser which didn’t).
But I still got the same exception. Apparently the JsonResult does checking of its own – so, the actual solution is not to return JsonResult, but ContentResult:
And there, 26MB returned as JSON without any issues. An alternative approach would be to write the JSON directly to the output (Response.Clear(); Response.ContentType = “application/json”; Response.Write(serializer.Serialize(myBigData);).