August 21, 2013

Lately I worked on a project that worked great on Visual Studio but upon deployment I kept get the error - "Operation is not valid due to the current state of the object". After doing some more tests, unfortunately, on production, I realised that the error is happening due to large data set that is returned from the database for the logged in user.


As a workaround for getting this error, an application key "aspnet:MaxHttpCollectionKeys" can be added with a large value like "2000". The default value for this key is "1000".

Web.config - App Settings
  1. <appSettings>
  2.   <add key="aspnet:MaxHttpCollectionKeys" value="2000" />
  3. </appSettings>


Reference: Shahed Kazi at