Click here to Skip to main content
13,409,492 members (41,069 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 21 Feb 2012

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

, 21 Feb 2012
Rate this:
Please Sign up or sign in to vote.
How to solve this error.

Whenever a postback is done, this error occurs when form fields are very large in number. The stack trace is:

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 the MaxHttpCollection value. Try adding the following setting in your web.config's <appsettings> block.

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

It can solve your problem. If you have very large records on your page, say 600 records in a 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. :-)


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


About the Author

Sarvesh Kumar Gupta
Software Developer (Senior) Edge Business Solution
India India
Working in Edge Business Solution as a Senior Software Developer. I have more than 7 years exp. in Microsoft Technologies. I have exp. in ASP.Net, C#, SQL 2000/2005/2008 R2, Javascript, Ajax, JQuery, MVC, LINQ etc.

You may also be interested in...

Comments and Discussions

GeneralThanx Pin
bhanu shrivastava19-Jul-12 3:35
memberbhanu shrivastava19-Jul-12 3:35 
General1000+ form fields on one page? That sounds a little excessiv... Pin
Marcus Kramer21-Feb-12 10:48
memberMarcus Kramer21-Feb-12 10:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180221.1 | Last Updated 21 Feb 2012
Article Copyright 2012 by Sarvesh Kumar Gupta
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid