Take the 2-minute tour ×

I get the following error:


when attempting to set the permissions of a list item with the following code:

 if (!listitem.HasUniqueRoleAssignments) 
    listitem.BreakRoleInheritance(false);//I got an error here 

How can I correct this error?

share|improve this question
add comment

1 Answer

What is calling BreakRoleInheritance? Let's say it is an Event Receiver, but whatever it is, you need to make sure that the user has adequate permissions. Just because a user can add or update items in a list, doesn't mean that user has rights to call BreakRoleInheritance. For that, the user must have Manage Permissions rights.

To ensure the proper permissions, it is safest to call BreakRoleInheritance in the context of the site collection system account:

if (!listitem.HasUniqueRoleAssignments) 
    Guid siteId = listitem.Web.Site.ID; 
    Guid webId = listitem.Web.ID;
    Guid listId = listitem.ParentList.ID;
    int itemId = listitem.ID;
    SPUserToken token = listitem.Web.Site.SystemAccount.UserToken;
    using (SPSite site = new SPSite(siteId, token))
        using (SPWeb web = site.OpenWeb(webId))
            SPList list = web.Lists[listId];
            SPListItem item = list.GetItemById(itemId);

A couple other things to check:

  1. If you are using elevated privileges, set allow unsafe updates to true.
  2. If versioning is enabled, be sure the item is checked in.
share|improve this answer
add comment

Your Answer


