Reputation: 61
""""""""""""""""""Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"""""""""""""""""
I tried all the answers but still now am getting this error anyone please help.
Upvotes: 4
Views: 16502
Reputation: 302
We had a json object returning from the web service. code was as below
JavaScriptSerializer s = new JavaScriptSerializer();
.
.
.
return s.Serialize(bomDataObject);
we had about 5000+ rows causing the above error in serialization.
visited the following links to get an idea of the maximum json size limits:
The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data. We set the code to following to work for our scenario for large data... ofcourse adds load on server and network to load data but it is huge data and we need to displau it !!
JavaScriptSerializer s = new JavaScriptSerializer();
s.MaxJsonLength = int.MaxValue;
.
.
.
.
.
return s.Serialize(bomDataObject);.
Upvotes: 1
Reputation: 3440
From the MSDN article linked by fejescoco, you must specify a maximum length in your configuration.
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="9001"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
Upvotes: 3
Reputation: 31
Be aware that the value of the MaxJsonLength property applies only when you explicitly create an instance of the JavaScriptSerializer class.
Upvotes: 1