Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When/why does SPUtility.ResolvePrincipal return a non-null SPPrincipalInfo with a PrincipalId of -1 ? I can manually assign rights to the user through the web interface. The user resides in an active directory. If I request a non existing user null is being returned as expected. The same logic works for a lot of other users.

SPPrincipalInfo principalInfo = SPUtility.ResolvePrincipal(currentWeb, objectPrincipal, SPPrincipalType.All, SPPrincipalSource.All, null, false);
if (principalInfo == null)
{
  result[i][j] = "Can not determine principalInfo for name: " + objectPrincipal;
  continue;
}
if (principalInfo.PrincipalId <= 0)
{
  result[i][j] = "Got invalid PrincipalId: " + principalInfo.PrincipalId + " in principalInfo for name: " + objectPrincipal;
  continue;
}

My log output:

Setting rights failed for user: DOMAIN\usr1 error: Got invalid PrincipalId: -1 in principalInfo for name: DOMAIN\usr1

Any ideas?

share|improve this question
    
Edit: after manually adding the rights for the user it wont return a PrincipalId of -1 for this user in the future. So it seems like I just need a way to do this "lazy user initialization" via code somehow? –  Chris Jan 8 '13 at 16:43
add comment

1 Answer

up vote 0 down vote accepted

When null is returned the user does not exist, when PrincipalId -1 is returned I have now used the EnsureUser method to make the existing user known to the sharepoint system.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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