0

My MVC3, C#, web application worked fine, until a week ago. No changes to data or code, yet now we're receiving

"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."

I've tried doing everything it seems, and finally this morning decided to just send a smaller set of data (50 records), and still have no luck. The odd thing is that the application works on Test, but not on Production.

The error received on the page is:

[InvalidOperationException: Error during serialization or deserialization using the JSON 
JavaScriptSerializer. The length of the string exceeds the value set on the 
maxJsonLength property.]   
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder    
output, SerializationFormat serializationFormat) +588689
System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, 
SerializationFormat serializationFormat) +74
System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +231
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext 
controllerContext, ActionResult actionResult) +13

System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,     
ResultExecutingContext preContext, Func`1 continuation) +264
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext 
controllerContext, IList`1 filters, ActionResult actionResult) +176
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,     
String actionName) +329
System.Web.Mvc.Controller.ExecuteCore() +115
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +94
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext 
requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult 
result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
+9048061
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& 
completedSynchronously) +184

The version of MVC on Test is 2.0.41116.0, and on Production is 2.0.41211.0. We're currently sending the json as a List<List<string>>, and the size is 1,932,123. But it's confusing as to why it works on Test, and not Production. I can't see any differences, but can anyone suggest something that I may have missed in checking? I've already tried updating the config file (which I know doesn't matter/work), and quite a few of the other suggestions online, but no dice.

MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
sharcfinz
  • 465
  • 1
  • 6
  • 24
  • http://www.shabdar.org/asp-net/77-system-invalidoperationexception-maximum-length-exceeded.html http://dotnetbyexample.blogspot.com.tr/2007/11/expanding-lenght-of-json-data-returned.html http://dotnetarchitect.wordpress.com/2008/10/14/using-json-some-observations/ – L.B Mar 06 '14 at 18:33
  • possible duplicate of [The length of the string exceeds the value set on the maxJsonLength property](http://stackoverflow.com/questions/11881198/the-length-of-the-string-exceeds-the-value-set-on-the-maxjsonlength-property) – mayabelle Mar 06 '14 at 18:35
  • The error is coming from the JavaScriptSerializer which is in the System.Web.Extensions assembly so you should probably check that one between your test and prod environments and see if it is consistent. – Craig W. Mar 06 '14 at 18:39
  • @Craig W. - the exported assemblies are the same in test and production; I recompiled on my machine, (and the page works locally), and built and exported to prod. Still no luck :( Am I missing something, you think? – sharcfinz Mar 10 '14 at 15:40

1 Answers1

0

You need to override ExecuteResult method of JsonResult.

Please go through below link :

http://brianreiter.org/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/

asb
  • 412
  • 3
  • 3