I have a function that checks if a group is a member of a group. I have 2 variations of the function, neither work as expected:
public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp)
{
return gp.IsMemberOf(pgp);
}
AND
public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp)
{
if (gp != null && pgp != null)
{
return pgp.Members.Contains(gp);
}
else
{
return false;
}
}
Both look promising, however always return false. When it comes time to call the GroupPrincipal.save method, an object already exists error is thrown.
I ran a foreach loop to get the names of the members of the parent group, and compared with the new member name to be added and there is no doubt the member does exist.
I could use LINQ to do string comparison on name, but its not ideal.
What? If anything am I doing wrong? Is there a better method to determine if a group exists in a group.
Using framework 3.5 - thanks in advance