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


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

When there is a postback with large number of form fields such error occurs.

Stack trace :
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes

By default, the maximum value of MaxHttpCollection is 1000.
To solve this error, increase the MaxHttpCollection value. Try adding the following setting in your web.config’s <appsettings> block.

<appSettings>

<add key=”aspnet:MaxHttpCollectionKeys” value=”2001″ />

</appSettings>

SQL: Alter script to change the Primarykey Column datatype


–This will drop the primary key constraint
ALTER TABLE [pTARGET_TYPE] DROP CONSTRAINT PK_TARGET_TYPE

–Alter datatype
ALTER TABLE [TARGET_TYPE] ALTER COLUMN [TARGET_TYPE_ID] INT NOT NULL

–Add Primary key constraint
ALTER TABLE [TARGET_TYPE] ADD CONSTRAINT PK_TARGET_TYPE PRIMARY KEY ([TARGET_TYPE_ID])