Monday, April 20, 2009

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

If you are getting this error, this means you are conceptually doing wrong somewhere.Ideally ajax scenarios are meant only for small to medium server side calls not for getting tons of data, and if you are getting a lot of data using the asynchronous request then you are asking for trouble.So in such scenarios it is best to go and implement server side logic.But what if you are at a stage where you can't change your application logic now.

1.So for such a situation there are two ways either implement paging in getting your data which is very simple if you are using jQuery with any other server side technology.

Here is a quick link which tells you how to enable paging and many other things in your custom code.

http://smallworkarounds.blogspot.com/2009/02/jquery-aspnet-how-to-implement.html

2.If you can't enable paging also then you are left with only one other solution which is not so good but if your service call is failing then it will prevent the service call from failing, but if you are loading large amount of data again if you prevent your service call from failing still your browser will go abrupt and seems like it has hanged, but if you still want to try then just make this entry in your web.config file to increase the max-request length of the json-request

<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"></jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>

Important thing to keep in mind is that the maximum value for the integer field is 2147483647 and this limit has to remain inside the bounds of this value.

Happy Programming!!!

Submit this story to DotNetKicks

del.icio.usSave Total0 users

3 comments:

Anonymous said...

Excellent! This was the solution for my google maps marker limitation!

Anonymous said...

Thanks so much. A huge help!!!!

Anonymous said...

ty very much!

Post a Comment