Tuesday, October 23, 2012

Error: Operation is not valid due to the current state of the object. TargetSite: Void ThrowIfMaxHttpCollectionKeysExceeded()


Scenario:

If a page has large amount of Control or a Grid View Control has large amount of record and do the postback, we might be got this exception.

Message: Operation is not valid due to the current state of the object. TargetSite: Void ThrowIfMaxHttpCollectionKeysExceeded()

StackTrace: at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection() Source: System.Web

Resolution:

To Solve this issue, we need to increse the "MaxHttpCollection" value. We need to set this value in web.config file.

<appsettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="5001"> </add>

</appsettings>