I have a workflow running when an item is adding to a document library. In this workflow, I have a code activity that I am attempting to set permissions to the list item. I am trying to break inheritance, and set some specific permissions. I've done this before so I'm not concerned with the code for this.
The issue that I am running in to is when checking the item back in to SharePoint. When I run checkin, I get the generic error saying
The security validation for this page is invalid. There is no exception thrown in the code and I can step over it without issue. However, after this code block, the error is in the logs and the workflow says
Failed to start (retrying). This workflow has worked numerous times prior to me adding this code activity.
Here is the code block I am working with (simplified, but non-functioning):
workflowProperties.Web.AllowUnsafeUpdates = true; SPListItem item = workflowProperties.Item; item.File.CheckOut(); item.BreakRoleInheritance(false); item.SystemUpdate(false); item.File.CheckIn("permissions updated"); workflowProperties.Web.AllowUnsafeUpdates = false;
Any ideas? I've tried running an
UndoCheckout() on the File, but the same result occurs.
The reason I was performing the checkout is that I found my workflow would end up with 'Failed on start (retrying)' after the item permissions have been set. The logs say
Microsoft.SharePoint.SPException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. ---> System.Runtime.InteropServices.COMException (0x8102006D): The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation
Ok, I can break role inheritance fine without checking in/out. The reason I had all of that in there was because I am attempting to assign new permissions, which I think requires the update. I had stripped that out when posting. This is a records library, and items are immediately declared records. That's the need for the check in/out.
I ended up moving this to an event receiver. Worked as expected.