SSRS error: Operation is not valid due to the current state of the object

Fri, Feb 10, 2012 One-minute read

If you’re using SSRS in SharePoint integrated mode, you may come across this error when using report parameters that have a high number of items in them. A recent security bulletin highlighted some issues and vulnerabilities in ASP.net, and a patch was released to cover some of the items. One of these was the maximum number of items you can have in a collection. If you exceed the limit, then you’ll likely get an error like:

System.Web.HttpException:
The URL-encoded form data is not valid. —> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
at System.Web.HttpRequest.FillInFormCollection()
— End of inner exception stack trace —
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.get_Form()

The workaround to this is to add the following to your web.config for your IIS application:

where 5000 is a number big enough to cover the number of items in your collection. Be aware of the security implications this could have. There’s some really useful info around the issue, here.