title: Active Directory login - DirectoryEntry inconsistent exception
body: <p>I need to validate the LDAP user by checking if there exists such a user name in the specified domain. For this I am using this code - </p>
  
  <pre><code>DirectoryEntry entry = new DirectoryEntry("LDAP://" + strDomainController);
  DirectorySearcher searcher = new DirectorySearcher(entry);
  searcher.Filter = "SAMAccountName=" + strUserName;
  SearchResult result = searcher.FindOne();
  return (result != null) ? true : false;
  </code></pre>
  
  <p>This is a method in a class library which I intened to reference and use whereever I need this functionality in my project.</p>
  
  <p>To test this, I created a simple test application. The test occurs like this - </p>
  
  <pre><code>Console.WriteLine(MyClassLib.MyValidateUserMethod("UserName", "Domain",ref strError).ToString());
  </code></pre>
  
  <p>The problem I am facing is that this works fine when I test it with my testapp but in my project, when I try to use the same method with the same credentials - The <code>DirectoryEntry</code> object throws an <code>"System.DirectoryServices.DirectoryServicesCOMException"</code> exception and the <code>search.Filter</code> fails and throws ex = {"Logon failure: unknown user name or bad password.\r\n"} exception.</p>
  
  <p>I have tried impersonation but that doesn't help. Somehow the same method works fine in mytestapp and doesn't work in my project. Both these applications are in my local dev machine. What am I missing? Any ideas?</p>