I am working with Active Directory with the .NET System.DirectoryServices.AccountManagement .NET System.DirectoryServices.AccountManagement . I noticed that Principal implements IDisposable , which causes some headache, since everything in this namespace inherits Principal .
eg. consider the following code to get all users in the group:
PrincipalContext domain = new PrincipalContext(ContextType.Domain); GroupPrincipal group = GroupPrincipal.FindByIdentity(domain, "MyGroup"); PrincipalSearchResult<Principal> users = group.GetMembers();
Each individual type in this fragment implements IDisposable , including all users returned by the search and the set of search results itself.
Eliminating domain and group objects doesn't really matter (this would be easy with the using() block), but what should I do with each result? Do I need to iterate over this users collection and dispose of each?
source share