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

Trying to debug a random error on a rather complex page, there is a good deal of MS-SQL which is where I started trouble shooting. However as of yet I haven't been able to narrow it down. Funny thing is when I debug the code locally in VS (against the same DB connection) I don't get an error. Yet when the code is run against IIS it throws the following error. Anyone encountered anything similar ?

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location
of the exception can be identified using the exception stack trace

Stack Trace:

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

[HttpException (0x80004005): The URL-encoded form data is not valid.]
   System.Web.HttpRequest.FillInFormCollection() +11482818
   System.Web.HttpRequest.get_Form() +157
   System.Web.HttpRequest.get_HasForm() +11483620
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +141
   System.Web.UI.Page.DeterminePostBackMode() +100
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean  includeStagesAfterAsyncPoint) +259

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Best Solution

Could it be in relation to this issue? A suggested workaround is to add the following in your web.config:

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

Scott Gu also blogged about this vulnerability discovered in ASP.NET.

Related Question