I'm writing some code that involves Active Directory. Is it generally acceptable to mix calls to System.DirectoryServices
with calls to System.DirectoryServices.AccountManagement
? Are the two libraries designed to be used interchangeably or should I choose one and stick to that?
Asked
Active
Viewed 70 times
0

Paul Matthews
- 2,164
- 5
- 20
- 29
1 Answers
0
Unless there is something specific I need that AccountManagement
doesn't do by creating new inherited classes I will try to stick to just using AccountManagment
with the extra classes, I have seen issues where you try to use both at the same time.

Community
- 1
- 1

Scott Chamberlain
- 124,994
- 33
- 282
- 431
-
One possible problem with AccountManagement is that it seems very slow when iterating through a large number of search results. It may not be feasible to use it all of the time?? – Paul Matthews Aug 12 '13 at 22:38
-
@PaulMatthews I ran in to a similar issue in the past. Depending on how you are iterating it may be making separate queries to the server. – Scott Chamberlain Aug 12 '13 at 23:04
-
Yes that does seem to be the case. Do you know if this behaviour can be modified? How did you solve the problem? – Paul Matthews Aug 13 '13 at 03:07
-
The way I solved it was by making a class that held the information I needed and copied the information I needed in to it. It is very easy to do using [Automapper](https://github.com/AutoMapper/AutoMapper). It will let you turn an array of `UserPrincipals` in to an array of `MyUserPrincipalDTO` or whatever you call your class with a simple call of `var collectionOfDtos = Mapper.Map
(collectionOfUserPrincipals);`. By doing it this way all the info is queried from the server all at once and accessing each element is much faster. – Scott Chamberlain Aug 13 '13 at 03:24 -
Ok I had a look at Automapper and it looks interesting but I'm not exactly sure how that would cause all queries to be run at once?? Does Automapper spin off a separate thread or something like that? Not sure how it all works under the hood? – Paul Matthews Aug 14 '13 at 23:09