Error 0x80005000 when using Directory Services in .NET

Thu, Jan 8, 2009 1-minute read

I am currently developing a deployment tool to help me do easy deployments of websites to many web servers at the same time.

To do this I am using a combination of WMI and Directory services in .NET.

When I tried out the tool on our production environment I got some COM exceptions.

Naturally I started looking at my code, trying different approaches, but to no avail.

I then later found our that to use the directory services together with IIS, you need to have IIS installed on the machine you are running the code from.

Even if you do not manipulate the local machine.

So e.g. a directory URL called IIS://machinename/W3SVC will not work, unless you install IIS on the local machine from where you run the code.

If IIS is not installed you will get an error like:

System.Exception: System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()

The code I was using was similar to below:

string issMetaBasePath = "IIS://Server/W3SVC";
using (DirectoryEntry dir = new DirectoryEntry(iisMetaBasePath))
{
    foreach (DirectoryEntry de in dir.Children)
    {