n trying to add a user to a newly created site, I got this error. Turns out that I needed to add the user’s domain to the SPRoleAssignment:
SPRoleAssignment oRoleAssignment = new SPRoleAssignment(“DOMAIN\\User_Alias”,”User_Alias@Somewhere.com”,”Display_Name”,”Notes”);
This now seems to find the user, but is giving me a security error when I try to update the role assignments: “The security validation for this page is invalid.” but at least it is finding the user.
The solution to that error is to set spNewWeb.AllowUnsafeUpdates = true;