MaxJsonLength and JavaScriptSerializer


#1

We’ve seen an issue where were occasionally get “Occasional exception with JSON JavaScriptSerializer “The length of the string exceeds [maxJsonLength]”

We’ve changed Miniprofiler.Settings.maxJsonLength but we can see in the code that setting is not always referred to and therefore we still get the error.

I can see that “StackExchange.Profiling/MiniProfiler.cs” does this:-

private static JavaScriptSerializer GetJsonSerializer()

362	            return new JavaScriptSerializer { MaxJsonLength = Settings.MaxJsonResponseSize };   

BUT StackExchange.Profiling/Helpers/ExtensionMethods.cs does this:-

73	            return o == null ? null : new JavaScriptSerializer().Serialize(o);

and

83	            return s.HasValue() ? new JavaScriptSerializer().Deserialize<T>(s) : null;

I think it should really respect MaxJsonLength = Settings.MaxJsonResponseSize in both cases.

Anyone wish to comment?

James


#2

I’ve also experienced that exception when an application using Entity Framework generates too many SQL calls under the hood. I noticed that the most recent code on github has switched to Json.NET, but the nuget packages haven’t been updated in a long time.