I am trying to connect and do simple functionalities such as search on an Active Directory using C#. However, I am stuck in a problem. I am using DirectorySearcher to search the directory. There are loads of entries in the directory.
This is the function
void RunThis()
{
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://" + domainName;
de.Username = username;
de.Password = password;
de.AuthenticationType = AuthenticationTypes.Secure;
DirectorySearcher deSearch = new DirectorySearcher(de);
//Skipping properties to load
try
{
deSearch.SearchScope = SearchScope.Subtree;
SearchResultCollection rescoll = deSearch.FindAll();
deSearch.Dispose();
rescoll.Dispose();
}
catch (Exception obj)
{
System.Console.WriteLine("Exception in getting results. {0}",obj.Message);
}
}
de.Dispose();
} // end of function
This is a sample function I trimmed down to. I could find a lot of posts which said that calling dispose explicitly of the DirectorySearcher or ResultCollection object will solve the problem.
However, I see that the memory used by the task is increasing constantly. There isnt much else going in the other part of the code. When i comment the function, the memory usage becomes stable.
Has anyone else faced the issue and found a solution?
PS: And there is no way out. I need to do the findall :(