title: Crashing with C# and Directory Services on XP
body: <p>I'm trying to do some simple data retrieval with C# and Directory Services, but for some reason it doesn't work on any XP machines. If I run my code on a Server 2003 machine, there are no problems. I've spent a fair bit of time trying to find out if maybe there's some redistributable I need on XP or if the functionality simply isn't there, but I've found references to other developers who have similar code working under XP. If anyone has any experience or advice to share, I'd appreciate it.</p>
  
  <p>A simple code snippet that's crashing for me:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.DirectoryServices;
  
  namespace IIS_Site_Query_Tool
  {
      public partial class Window1 : Window
      {
          public Window1()
          {
              InitializeComponent();
  
              DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
              foreach (DirectoryEntry Site in W3SVC.Children)
              {
                  //Do some data processing
              }
          }
      }
  }
  </code></pre>
  
  <p>Running this under XP gives me the folowing error with an HRESULT of -2147463168:</p>
  
  <pre><code>System.Runtime.InteropServices.COMException was unhandled
    Message="Unknown error (0x80005000)"
    Source="System.DirectoryServices"
    ErrorCode=-2147463168
    StackTrace:
         at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
         at System.DirectoryServices.DirectoryEntry.Bind()
         at System.DirectoryServices.DirectoryEntry.get_IsContainer()
         at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
         at System.DirectoryServices.DirectoryEntries.GetEnumerator()
         ...
  </code></pre>
  
  <p>Googling the various pieces of information in the error lead me to think that it's a pretty generic COM interop error, and I'm out of ideas at this point. Any help is appreciated!</p>