title: JavaScriptSerializer.MaxJsonLength exceeded
body: <p>My MVC3, C#, web application worked fine, until this morning. 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."</p>
  
  <p>I've tried upping the limit on the web config file (which I then read does nothing, and it doesn't in my case):</p>
  
  <pre><code>    &lt;system.web.extensions&gt;
        &lt;scripting&gt;
          &lt;webServices&gt;
            &lt;jsonSerialization maxJsonLength="2147483644"&gt; &lt;/jsonSerialization&gt;
          &lt;/webServices&gt;
        &lt;/scripting&gt;
      &lt;/system.web.extensions&gt;
  </code></pre>
  
  <p>The original return statement was:</p>
  
  <pre><code>    return Json(new DataTableCustom(data), JsonRequestBehavior.AllowGet);
  </code></pre>
  
  <p>where the definition of the DataTableCustom is:</p>
  
  <pre><code>    public class DataTableCustom
      {
        public List&lt;List&lt;string&gt;&gt; aaData { get; set; }
  
        public DataTableCustom(List&lt;List&lt;string&gt;&gt; data)
        {
            aaData = data;
        }
      }
  </code></pre>
  
  <p>I've tried using this as well, with no luck:</p>
  
  <pre><code>    var serializer = new JavaScriptSerializer();
      serializer.MaxJsonLength = Int32.MaxValue;
      serializer.RecursionLimit = 100;
  
      var resultData = new { Value = "foo", Text = "bar" };
      var container = new ContentResult
      {
        Content = serializer.Serialize(new DataTableCustom(data)),
        ContentType = "application/json"
      };
  
      return Json(container, JsonRequestBehavior.AllowGet);
  </code></pre>
  
  <p>And I've tried variations of that and everything else with it. But still no luck. The odd thing is that it happens on Production, but not on always on Test, depending on the MaxJsonLength, or the return statement.</p>
  
  <p>Can anyone else see something that I'm not trying? I've run out of things to try.</p>