Mar 03, 2014 10:40 AM|smirnov|LINK
I mean, the Group I am searching is a subgroup.
This is the reason of the behaviour with "not all groups". The groups are all and the code was correct, but the "memberOf" property lists only parent groups. You can still use same code but you would need to do extra loops to check for nested groups
I'm not sure why the other code is not working for you, but it seems the problem is not in the groups.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "Company.com", "DC=SomeDC,DC=COM", username, Password);
UserPrincipal up = UserPrincipal.FindByIdentity(ctx, strUserName);
PrincipalSearchResult<Principal> groups = up.GetAuthorizationGroups();
var iterGroup = groups.GetEnumerator();
you receive an error
GetAuthorizationGroups gives "Object reference not set error"
then it sounds like UserPrincipal is null and FindByIdentity did not return any user. It means you need to debug and see why PrincipalContext or FindByIdentity return null.
According to http://stackoverflow.com/questions/12041459/active-directory-memberof-property-doesnt-contain-nested-security-groups the GetAuthorizationGroups()
method should return nested groups...