title: C# Active Directory Invoke "ChangePassword" cannot contact domain
body: <p>I have the following code as part of a web application for my Active Directory users to be able to update their passwords (for active directory and gmail at the same time).  I am using C# with System.DirectoryServices.AccountManagement.</p>
  <p>This code worked until <em>yesterday</em></p>
  <pre><code>try
  {
      State.log.WriteLine(&quot;Connecting LDAP.&quot;);
      string ldapPath = &quot;LDAP://192.168.76.3&quot;;
      DirectoryEntry directionEntry = new DirectoryEntry(ldapPath, domainName + &quot;\\&quot; + userName, currentPassword);
      if (directionEntry != null)
      {
          DirectorySearcher search = new DirectorySearcher(directionEntry);
          State.log.WriteLine(&quot;LDAP Connected, searching directory for SAMAccountName&quot;);
          search.Filter = &quot;(SAMAccountName=&quot; + userName + &quot;)&quot;;
          SearchResult result = search.FindOne();
          if (result != null)
          {
              State.log.WriteLine(&quot;Getting User Entry.&quot;);
              DirectoryEntry userEntry = result.GetDirectoryEntry();
              if (userEntry != null)
              {
                  State.log.WriteLine(&quot;Setting Password&quot;);
                  if (force)
                  {
                      userEntry.Invoke(&quot;SetPassword&quot;, new[] { newPassword });
                  }
                  else
                  {
                      userEntry.Invoke(&quot;ChangePassword&quot;, new object[] { currentPassword, newPassword });
                  }
                  userEntry.CommitChanges();
                  State.log.WriteLine(&quot;Changes Committed to ActiveDirectory.&quot;);
              }
              else
              {
                  State.log.WriteLine(&quot;Could not get user Entry...&quot;);
              }
          }
          else
          {
              State.log.WriteLine(&quot;Search returned no results.&quot;);
          }
      }
      else
      {
          State.log.WriteLine(&quot;Could not connect to LDAP with given username and passwd&quot;);
      }
  }
  </code></pre>
  <p>Since yesterday, this code makes it to the line:</p>
  <pre><code>userEntry.Invoke(&quot;ChangePassword&quot;, new object[] { currentPassword, newPassword });
  </code></pre>
  <p>and then throws the following exception:</p>
  <blockquote>
  <p>[8:37:00 AM] :  Password Requirements Met.</p>
  <p>[8:37:00 AM] :  Connecting LDAP.</p>
  <p>[8:37:00 AM] :  LDAP Connected, searching directory for SAMAccountName</p>
  <p>[8:37:01 AM] :  Getting User Entry.</p>
  <p>[8:37:01 AM] :  Setting Password</p>
  <p>[8:37:01 AM] :  Failed to reset Windows Password for jason.</p>
  <hr />
  <p>Exception has been thrown by the target of an invocation.</p>
  <hr />
  <p>The system cannot contact a domain controller to service the authentication request. Please try again later. (Exception from HRESULT: 0x800704F1)</p>
  </blockquote>
  <p>The &quot;force&quot; option using &quot;SetPassword&quot; still works just fine, but the &quot;ChangePassword&quot; method which can be invoked by non-administrator users does not.</p>