Saturday, September 20, 2008

SPListItem.Update() throws error Operation is not valid due to the current state of the object.

Problem:
When running SPListItem.Update commands inside SPSecurity.RunWithElevatedPrivileges block in the .net application in the sharepoint virtual directory environment then you get error: Operation is not valid due to the current state of the object.

When you can add the procedure in the SPSecurity.RunWithElevatedPrivileges block then some time also Call Stack error has occured.
When you can install your webpart or Usercontrol in the sharepoint page then this type error is not occurred.
Instead you should instantiate the SPSite or SPWeb there and call Update afterwards.