title: How to overcome the "The member's SID could not be resolved" error when checking if user is a member of group?
body: <p>We have a process that requires to check whether a particular user is a member of local Administrators group.</p>
  
  <p>The code that checks that looks like the following:</p>
  
  <pre><code>using (PrincipalContext context = new PrincipalContext(ContextType.Machine, null))
  {
      UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, sUserName);
      if (user != null)
      {
           SecurityIdentifier adminsGroupSID = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
           GroupPrincipal group = GroupPrincipal.FindByIdentity(context, IdentityType.Sid, adminsGroupSID.Value);
           if (group != null)
           {
               if (user.IsMemberOf(group))
                   return 0;
           }
      }
  }
  </code></pre>
  
  <p>When the group has accounts (e.g. domain accounts) that were removed, we're getting a PrincipalOperationException and a message "An error (1332) occurred while enumerating the group membership.  The member's SID could not be resolved."</p>
  
  <p>Is there any way to overcome this without:
  a) Removing manually the orphaned SIDs from the group
  b) Not ignoring it?</p>
  
  <p>Thanks</p>