Powered by Blogger.

Saturday, February 15, 2014

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



In this post we will discuss how we will resolve the issue "Operation is not valid due to the current state of the object". Also you can check out some post:

- File upload and thumbnail creation in Asp.Net

- How to make scaling animation effect using AnimationExtender Control in asp.net

- How to display serial number automatically in GridView in asp.net?

Below is the full error message:

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

Stack Trace:

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

Reason:
This error ususally comes due to the MaxHttpCollection value inside web.config file.

Solution:
To resolve this issue, increase MaxHttpCollection value in web.config file like below:

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

  </appSettings>

Hope this will solve your problem.