In this article I will explain how to solve the exception (error) occurring during AJAX calls in ASP.Net i.e. Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
The above exception (error) occurs in ASP.Net when AJAX calls are made to PageMethods (WebMethods) using jQuery AJAX or ScriptManager and the length of the AJAX Response exceeds the default predefined limit of 2097152 characters i.e. 4 MB.
 
 
Problem
The following exception (error) occurs in ASP.Net when AJAX calls are made to PageMethods (WebMethods) using jQuery AJAX or ScriptManager.
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
ASP.Net AJAX Error: The length of the string exceeds the value set on the maxJsonLength property
 
 
Cause
This exception (error) occurs in ASP.Net when AJAX calls are made to PageMethods (WebMethods) using jQuery AJAX or ScriptManager and the length of the AJAX Response exceeds the default predefined limit of 2097152 characters i.e. 4 MB as per MSDN.
 
 
Solution
The solution to this problem is to set a higher value of maxJsonLength property through Web.Config configuration using the system.web.extensions section as shown below.
<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="819200000" />
        </webServices>
    </scripting>
</system.web.extensions>