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

In this asp.net tutorial you will find the solution of this nasty error, Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. This error comes when you want to get huge amount of data through JSON format in your asp.net page. The only thing that you have to do is to add following code snippet in the web.config file of your project between <configuration> and </configuration> tag

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


I have set maximum value to MaxJsonLength property according to current situation. As per documented by Microsoft, MaxJsonLength Property gets or sets the maximum length of JSON strings that are accepted by the JavaScriptSerializer class.The MaxJsonLength property cannot be unlimited, it is an integer property that has by default 2097152 characters (approximately. 4MB of data). But my suggestion for you is to don't show such huge amount of data at once in front of user because it might be hang his browser, please use pagination for better performance and consistency. I will write some posts about pagination in asp.net and pagination in asp.net with jquery.

I hope you will find this article helpful to get rid of this nasty error.

0 comments: