Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Error - Operation is not valid due to the current state of the object.

4.67/5 (5 votes)
24 Jan 2012CPOL 66.1K  
Error - Operation is not valid due to the current state of the object.
Whenever a post back is done, this error occurs when form fields are very large in numbers.
The stack trace is:
C#
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection()


By default, the maximum value of MaxHttpCollection is 1000.

To solve this error, increase MaxHttpCollection value. Try adding the following setting in your web.config's <appsettings> block.

XML
<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2001" />
 </appSettings>


It can solve your problem. if you have very large records on your page, suppose 600 records in grid and you click on submit, then increase the value of MaxHttpCollection.

Then change value 2000 to 5000 and test again. It will be resolved. :-D

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)