title: Active Directory: The server could not be contacted using DirectorySearcher
body: <p>I keep getting the error <strong>The server could not be contacted.</strong> When i'm trying to run my code:</p>
  
  <p>I've searched for a few hours, and i'm still unable contact the server.</p>
  
  <pre><code>DirectorySearcher directorySearcher = new DirectorySearcher();
  string path = directorySearcher.SearchRoot.Path;
  DirectoryEntry directoryEntry = new DirectoryEntry(path);
  
  PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk");
  //GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")");
  GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")");
  
  
  if (group != null)
  {
      foreach (Principal principal in group.Members)
      {
          UserPrincipal tu = principal as UserPrincipal;
  
          DirectoryEntry de = tu.GetUnderlyingObject() as DirectoryEntry;
          var store = de.InvokeGet("physicalDeliveryOfficeName").ToString();
          var storeNumber = de.InvokeGet("description").ToString();
  
          employees.Add(new AdEmployees() { name = principal.Name, phone = tu.VoiceTelephoneNumber, email = tu.EmailAddress, store = store.ToString(), storeNumber = storeNumber.ToString(), link = GenerateLink(principal.Name) });
      }
  }
  </code></pre>
  
  <p><strong>Note:</strong> I changed my domain where the AD is located to domain. </p>