title: JSONConvert.SerializeObject Maximum Length
body: <p>Recently discovered that existing serialization code fails when the object to convert is too large. I know how to increase the maximum length in .NET's JavascriptSerializer. But how do I do the same thing in JsonConvert.SerializeObject?</p>
  
  <p>References to web.config setting:</p>
  
  <p><code>&lt;jsonSerialization maxJsonLength="50000000"/&gt;</code></p>
  
  <p>Say that it is only respected by WCF. We aren't using WCF. This is a simple .NET library that requires serialization of objects.</p>
  
  <p>The relevant code is:</p>
  
  <pre><code>        public static string Serialize(object value)
          {
              return JsonConvert.SerializeObject(value, SerializerSettings);
          }
  </code></pre>
  
  <p>This is how I create the settings:</p>
  
  <pre><code>        private static JsonSerializerSettings SerializerSettings
          {
              get
              {
                  var settings = new JsonSerializerSettings();
                  settings.Converters.Add(new StringEnumConverter());
                  settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                  settings.NullValueHandling = NullValueHandling.Ignore;
                  return settings;
              }
          }
  </code></pre>
  
  <p>I don't see a property I need in JsonSerializerSettings. My object is multilayered but mostly of string types. I convert an uploaded file and store it as a string. The size of that file is the element that I am changing when I see the failire.  </p>
  
  <p>Unfortunately the library I am using doesn't log so I can't find the exact error. But the code works with smaller files (&lt;150KB) and fails with larger ones >500KB.</p>