By Mark Highfield

2014-03-20 13:12:29 8 Comments

I'm getting this error:

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

I have googled answers for this and have found 2 answers, neither of which seem to be working for me. I have tried to add the maxJsonLength setting to the web.config but it's being ignored. As well, I have tried in the C# code to set MaxJsonLength = int.MaxValue; but I am using MVC 2.0 and it appears this only works in MVC 4? Can anyone help me set the maxJsonLength property properly? Here is where I'm getting the error.

 public override void OnActionExecuted(ActionExecutedContext filterContext)
        var result = filterContext.Result as ViewResult;
        if (result == null)

        var jsonResult = new JsonResult
                              Data = result.ViewData.Model, 
                              JsonRequestBehavior = JsonRequestBehavior.AllowGet

        filterContext.Result = jsonResult;


@Mark Highfield 2014-03-20 17:18:44

Got it, using the following code

 public ActionResult MyFancyMethod()
     var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
     var result = new ContentResult
         Content = serializer.Serialize(myBigData),
         ContentType = "application/json"
     return result;

@user3409638 2014-03-20 14:23:39

I am not sure it works or not but i found some solution , please try below

               <jsonSerialization maxJsonLength="2147483644"/>


public ActionResult SomeControllerAction()
  var jsonResult = Json(veryLargeCollection, JsonRequestBehavior.AllowGet);
  jsonResult.MaxJsonLength = int.MaxValue;
  return jsonResult;

@Mark Highfield 2014-03-20 15:00:13

I tried both of these options. The Web.config option is ignored, and unless I'm doing something wrong, it appears MVC2 doesn't have the MaxJsonLength property available.

Related Questions

Sponsored Content

29 Answered Questions

[SOLVED] Can I set an unlimited length for maxJsonLength in web.config?

9 Answered Questions

[SOLVED] Why can't Python parse this JSON data?

  • 2010-05-14 15:54:20
  • michele
  • 2646106 View
  • 1454 Score
  • 9 Answer
  • Tags:   python json parsing

15 Answered Questions

[SOLVED] MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer

1 Answered Questions

Asp.NET Core How to set maxJsonLength

1 Answered Questions

1 Answered Questions

3 Answered Questions

[SOLVED] Increase json response maxJsonLength in MVC 4

3 Answered Questions

1 Answered Questions

[SOLVED] ASP.NET MVC Catching Serialisation maxJsonLength violation

  • 2015-06-02 10:51:11
  • Stephen A
  • 390 View
  • 0 Score
  • 1 Answer
  • Tags:   c# json

Sponsored Content