I wrote the following code:

SPGroup spGroupItem = web.SiteGroups["Site Owners"];
SPPrincipal principal = spGroupItem;
SPRoleAssignment oRoleAssignment = web.RoleAssignments.GetAssignmentByPrincipal(principal);
foreach (SPRoleDefinition inRole in oRoleAssignment.RoleDefinitionBindings)

But this code gives following exception for some groups.

Can not find the principal with id: xxx

  • 2
    where are you getting spweb object ? try using the web object within the runwithelevatedprivielges : try { { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(strSite)) { using (SPWeb web = site.OpenWeb()) {
    – samolpp2
    Dec 30, 2015 at 7:36
  • 2
    try this too: SPPrincipal pr = SPContext.Current.Web.Groups[0]; if (pr is SPGroup) { Console.WriteLine("Group"); }
    – samolpp2
    Dec 30, 2015 at 7:41

1 Answer 1


There can be some attributes missing for the groups/users. Cross check the properties of the group along with other groups. Is it custom permission level defined group which is throwing this exception?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.