# MaxJsonLength and JavaScriptSerializer

**URL:** <https://community.miniprofiler.com/t/maxjsonlength-and-javascriptserializer/405>\
**Category:** .NET\
**Created:** [October 19, 2015, 4:42am UTC](https://community.miniprofiler.com/t/maxjsonlength-and-javascriptserializer/405 "2015-10-19T04:42:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipolar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/dipolar/32/855_2.png) [@dipolar](https://community.miniprofiler.com/u/dipolar)\
**Post date:** [October 19, 2015, 4:42am UTC](https://community.miniprofiler.com/t/maxjsonlength-and-javascriptserializer/405/1 "2015-10-19T04:42:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GiddyUpHorsey](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/giddyuphorsey/32/906_2.png) [@GiddyUpHorsey](https://community.miniprofiler.com/u/GiddyUpHorsey)\
**Post date:** [July 20, 2017, 11:58pm UTC](https://community.miniprofiler.com/t/maxjsonlength-and-javascriptserializer/405/2 "2017-07-20T23:58:48Z")

</div>

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](http://Json.NET), but the nuget packages haven’t been updated in a long time.
