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


Getting the error “Operation is not valid due to the current state of the object“, while debugging. And you want reason and solution for this error. So here is the complete information related to this problem.

It Is Microsoft .NET framework vulnerabilities which occurs when form field are very large in number. By default value for MaxHttpCollection is 1000. As the maxhttpcollection crosses the default limit it throws an error “Operation is not valid due to the current state of the object”. Now you are thinking how this maxhttpconnection has been reached accidently so that you are getting the same error. The most common reason behind is that you are submitting say 1000 record from your page, this increases the maxhttpconnections.

To solve this problem increase the value of MaxHttpCollection. This can be increase by adding a value to appsetting tag in the web.config file. And if you are still getting the error then increase some more value and again check, the value required to solve your problem depend on the number of record you are submitting.

 XML |  copy code |? 
    <add key="aspnet:MaxHttpCollectionKeys" value="3000" />


In this way you can change the limit on the maximum number of posted form values. I hope you got the solution. If you still have doubt then your comments are welcome always.

Leave a Comment

Your email address will not be published.