I am trying to check if a user is a member of a group like:
if (conditionalGroup != null)
{
if (!currentUser.IsMemberOf(conditionalGroup))
{
_logger.Debug("Adding user to Specific group.");
conditionalGroup.Members.Add(currentUser);
conditionalGroup.Save();
}
conditionalGroup.Dispose();
}
However it fails with this: An error (1789) occurred while enumerating the group membership. The member's SID could not be resolved.
This group is the Users group on the local machine. I also do the same thing with the IIS_IUSRS group and that one is fine. This just started today on my build machine and has always worked before. Is this a bug or am I doing something wrong?
Here is how I create the User:
pc = new PrincipalContext(ContextType.Machine); currentUser = UserPrincipal.FindByIdentity(pc, u.UserName);
if (currentUser == null)
{
currentUser = new UserPrincipal(pc)
{
Name = u.UserName,
Description = u.UserDescription,
UserCannotChangePassword = false,
PasswordNeverExpires = true
};
currentUser.SetPassword(u.UserPassword);
currentUser.Save();
}