Showing posts with label MaxHttpCollectionKeys. Show all posts
Showing posts with label MaxHttpCollectionKeys. Show all posts

Monday, April 23, 2012

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


When the number of controls / fields in an Asp.Net 3.0 form exceeds 1000, the following error message will be thrown.

Operation is not valid due to the current state of the object.  
  at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()    
  at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)    
  at System.Web.HttpRequest.FillInFormCollection()



This is because the Microsoft security update MS11-100 limits the maximum number of form keys, files, and JSON members to 1000 in an HTTP request.

When there is a HTTP request requesting for a page which has more than 1000 fields/controls, this exception in thrown.

The good thing is, that there is a fix for the issue, which can be made by altering the settings in the web.config file. Adding the following line to the <appSettings> section will increase the limit from 1000 to 2000, you can configure the <appSettings> section based on your needs.

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

For more information please visit the following post in Microsoft’s support center.




http://support.microsoft.com/kb/2661403