There is not much more to say here. In this case, we just create a runtimecallable wrapper (RCW) interop assembly for the entire activeds.tlb type library using tlbimp.exe or Visual Studio .NET. For Visual Studio .NET, this is as simple as using Project > Add Reference and selecting activeds.tlb from the COM tab. If we are not using Visual Studio .NET, we need to use the command-line tool from the .NET SDK, called tlbimp.exe. Here is a sample command line for using this tool (watch for the wrap):
tlbimp.exe activeds.tlb /out:activedsNET.dll /namespace:ActiveDS
This will create an RCW called activedsNET.dll that we should deploy with our application. If necessary, we can also provide a strong name for the generated assembly so that we can call it from our own strong-named assemblies as well. The .NET runtime includes a security restriction that prevents strongly named assemblies from calling into assemblies that are not strongly named. For more information about code access security (CAS) policy as it relates to strong names, see Chapter 8.
The advantages of this approach are that it is easy and the performance is good.
The downsides of this approach are as follows.
Because of the ease of use of this approach, we have tended to use it throughout the book, even though it might not be ideal for all situations.
Microsoft could actually improve on the second point by providing what is called a Primary Interop Assembly (PIA) for activeds.dll, similar to what it does with the Microsoft Office automation libraries, which is handcrafted to address these problems and includes a strong name. However, Microsoft has thus far not elected to do this for us.
Part I: Fundamentals
Introduction to LDAP and Active Directory
Introduction to .NET Directory Services Programming
Binding and CRUD Operations with DirectoryEntry
Searching with the DirectorySearcher
Advanced LDAP Searches
Reading and Writing LDAP Attributes
Active Directory and ADAM Schema
Security in Directory Services Programming
Introduction to the ActiveDirectory Namespace
Part II: Practical Applications
Part III: Appendixes
Appendix A. Three Approaches to COM Interop with ADSI
Appendix B. LDAP Tools for Programmers
Appendix C. Troubleshooting and Help