How to fix the server method failed Maximum length exceeded error when using ASP.NET AJAX

by APIJunkie 14. March 2008 01:21

If you are using ASP.NET AJAX to create RIA's (Rich Internet Applications) you might run into the maximum length exceeded error.

This error occurs when you are trying to send too much data using ASP.NET AJAX from the client to the server and vice versa.

On the function call stack level this error occurs at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize or at System.Web.Script.Services.RestHandler.InvokeMethod depending if you are sending or receiving data.

The problem is that the default maximum size (102400 characters) does not suffice when you try to transfer a significant amount of data.

To increase the maximum allowed send/receive data you need to change the MaxJsonLength Property.

To change the MaxJsonLength Property you can edit your web.config file.

Look for the following commented section in the web.config file:

 

<!--
Uncomment this line to customize maxJsonLength and add a custom converter -->

<!--

<jsonSerialization maxJsonLength="500">

<converters>

<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

</converters>

</jsonSerialization>

-->

 

Convert it to something along the following lines (see note below):

 

<!--
Uncomment this line to customize maxJsonLength and add a custom converter -->

<jsonSerialization maxJsonLength="200000"><

converters>

<!--<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>--></

converters>

</jsonSerialization>

 

Note that in the example above the max size was set to 200,000 characters.

You should calculate and test the size you will need for your data (there might be a few bytes of overhead so take that into account).

 

Tags:

.NET | AJAX | PRB | JSON | How To

Comments

3/14/2008 1:39:29 AM #

trackback

Trackback from DotNetKicks.com

How to fix the server method failed Maximum length exceeded error

DotNetKicks.com

3/16/2008 10:32:43 PM #

cloink

Thanks, this has saved my day! Smile

cloink Belgium

Comments are closed

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon