"Object reference not set to an instance of an object" when reading C# GroupPrincipal.Members.Count
It seems that there is a bug in the .NET 3.5 managed library System.DirectoryServices.AccountManagement. When you try and view the Members.Count property of a Global group the system throws the following exception. System.NullReferenceException: Object reference not set to an instance of an object. at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.BookmarkAndReset() at System.DirectoryServices.AccountManagement.PrincipalCollection.get_Count() It is however possible to enumerate the members of the group The following sample code demonstrates the issue where the domain is called demonstration.int and the group name is SampleGroup. GroupPrincipal Group = GroupPrincipal .FindByIdentity( new PrincipalContext ( ContextType .Domain, "demonstration.int" ), "SampleGroup" ); MessageBox .Show(Group.Members.Count.ToString()); If anyone has any further information please feel free to post a comment. I've not...