I am using the autocomplete feature of jQuery. When I try to retrieve the list of more then 17000 records (each won't have more than 10 char length), it's exceeding the length and throws the error:
Exception information:
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Can I set an unlimited length for maxJsonLength
in web.config
? If not, what is the maximum length I can set?
Alternative ASP.NET MVC 5 Fix:
(Mine is similar to MFCs answer above with a few small changes)
I wasn't ready to change to Json.NET just yet and in my case the error was occurring during the request. Best approach in my scenario was modifying the actual
JsonValueProviderFactory
which applies the fix to the global project and can be done by editing theglobal.cs
file as such.add a web.config entry:
and then create the two following classes
This is basically an exact copy of the default implementation found in
System.Web.Mvc
but with the addition of a configurable web.config appsetting valueaspnet:MaxJsonLength
.you can write this line into Controller
you can also write this line into
web.config
`
To be on the safe side, use both.
Simply set MaxJsonLength proprty in MVC's Action method
if you are still getting error after web.config setting like following:
I solved it by following:
I hope this should help.
In MVC 4 you can do:
in your controller.
Addition:
For anyone puzzled by the parameters you need to specify, a call could look like this:
I followed vestigal's answer and got to this solution:
When I needed to post a large json to an action in a controller, I would get the famous "Error during deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.\r\nParameter name: input value provider".
What I did is create a new ValueProviderFactory, LargeJsonValueProviderFactory, and set the MaxJsonLength = Int32.MaxValue in the GetDeserializedObject method
}
Then, in the Application_Start method from Global.asax.cs, replace the ValueProviderFactory with the new one: