Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to resolve error - Operation is not valid due to the current state of the object

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.66k
    Comment on it

    Hi all,

    While working with large data bind on a page and whenever an event "page.postback" is done, an exception "Operation is not valid due to the current state of the object." occurs due to the very large number of form fields. The stack trace is:

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

    This exception raises because Microsoft Security Update limits number of keys in Forms collection during HTTP POST request.
    The default maximum value of MaxHttpCollection is 1000.
    To eliminate this exception, increase in numbers of MaxHttpCollection is required. Following changes are mandatory to done in Web.config file:

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


    Happy Coding... :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: