Click here to Skip to main content
15,795,712 members
Articles / Web Development / ASP.NET
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.67/5 (5 votes)
24 Jan 2012CPOL 63.5K   2   7
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)



Comments and Discussions

 
GeneralRe: offcourse! Pin
ThatsAlok31-Jan-12 19:56
ThatsAlok31-Jan-12 19:56 
GeneralReason for my vote of 5 thanks for tip! Pin
beginner201119-Feb-12 16:05
beginner201119-Feb-12 16:05 
GeneralExcellent - than you, solved my problem. You learn something... Pin
mrOneness29-Jan-12 9:43
mrOneness29-Jan-12 9:43 
GeneralRe: Please vote for this. Pin
Sarvesh Kumar Gupta31-Jan-12 3:00
Sarvesh Kumar Gupta31-Jan-12 3:00 
Generali Increased the value to 5000 and it was working fine. I had... Pin
mr.akirame28-Jan-12 2:02
mr.akirame28-Jan-12 2:02 
GeneralThnks Helped me Pin
mr.akirame28-Jan-12 1:57
mr.akirame28-Jan-12 1:57 
GeneralJust a note, MaxHttpCollection was changed to be 1000 in a U... Pin
sergiogarcianinja24-Jan-12 13:49
sergiogarcianinja24-Jan-12 13:49 

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.