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?
References to web.config setting:
<jsonSerialization maxJsonLength="50000000"/>
Say that it is only respected by WCF. We aren't using WCF. This is a simple .NET library that requires serialization of objects.
The relevant code is:
public static string Serialize(object value)
{
return JsonConvert.SerializeObject(value, SerializerSettings);
}
This is how I create the settings:
private static JsonSerializerSettings SerializerSettings
{
get
{
var settings = new JsonSerializerSettings();
settings.Converters.Add(new StringEnumConverter());
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.NullValueHandling = NullValueHandling.Ignore;
return settings;
}
}
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.
Unfortunately the library I am using doesn't log so I can't find the exact error. But the code works with smaller files (<150KB) and fails with larger ones >500KB.