FindByIdentity in System.DirectoryServices.AccountManagment Memory Issues

Posted by MVC Fanatic on Stack Overflow See other posts from Stack Overflow or by MVC Fanatic
Published on 2009-08-20T12:13:34Z Indexed on 2010/03/18 17:01 UTC
Read the original article Hit count: 499

I'm working on an active directory managament application. In addition to the typical Create A New User, Enable/Disable an account, reset my password etc. it also managages application permissions for all of the clients web applications. Application management is handled by thousands of AD groups such as which are built from 3 letter codes for the application, section and site, there are also hundreds of AD groups which determine which applications and locations a coordinator can grant rights to. All of these groups in turn belong to other groups so I typically filter the groups list with the MemberOf property to find the groups that a user directly belongs to (or everyone has rights to do everything). I've made extensive use of the System.DirectoryServices.AccountManagment namespace using the FindByIdentity method in 31 places throughout the application. This method calls a private method FindPrincipalByIdentRefHelper on the internal ADStoreCtx class. A SearchResultCollection is created but not disposed so eventually typically once or twice a day the web server runs out of memory and all of the applications on the web server stop responsing until iis is reset because the resources used by the com objects aren't ever relased.

There are places where I fall back to the underlying directory objects, but there are lot of places where I'm using the properties on the Principal - it's a vast improvement over using the esoteric ad property names in the .Net 2.0 Directory services code.

I've contacted microsoft about the problem and it's been fixed in .Net 4.0 but they don't currently have plans to fix it in 3.5 unless there is intrest in the community about it.

I only found information about it in a couple of places

the MDSN documentation in the community content state's there is a memory leak at the bottom (guess I should have read that before using the the method)

http://msdn.microsoft.com/en-us/library/bb345628.aspx

And the class in question is internal and doesn't expose SearchResultsCollection outside the offending method so I can't get at the results to dispose them or inherit from the class and override the method.

So my questions are

Has anyone else encountered this problem? If so were you able to work around it?

Do I have any option besides rewriting the application not using any of the .Net 3.5 active directory code?

Thanks

© Stack Overflow or respective owner

Related posts about active-directory

Related posts about directoryservices