title: UserPrincipal.GetGroups fails with unknown error
body: <p>I am trying to get all Active Directory groups for a user, with the following code:</p>
  
  <pre><code>    private static IEnumerable&lt;string&gt; GetGroupNames(string userName)
      {
          using (var context = new PrincipalContext(ContextType.Domain))
          {
              using (var userPrincipal = UserPrincipal.FindByIdentity(context, userName))
              {
                  var groupSearch = userPrincipal.GetGroups(context);
                  var result = new List&lt;string&gt;();
                  foreach (var principal in groupSearch)
                  {
                      Log.LogDebug("User {0} is member of group {0}", userPrincipal.DisplayName, principal.DisplayName);
                      result.Add(principal.SamAccountName);
                  }
                  return result;
              }
          }
      }
  </code></pre>
  
  <p>This code correctly finds the user principal, but fails when GetGroups is called with a PrincipalOperationException: Unknown error (0x80005000).</p>
  
  <p>Root exception:</p>
  
  <pre><code>   at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOf(Principal foreignPrincipal, StoreCtx foreignContext)
     at System.DirectoryServices.AccountManagement.Principal.GetGroupsHelper(PrincipalContext contextToQuery)
     at System.DirectoryServices.AccountManagement.Principal.GetGroups(PrincipalContext contextToQuery)
     at [line of the GetGroup call]
  </code></pre>
  
  <p>Inner exception (COMException):</p>
  
  <pre><code>   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
     at System.DirectoryServices.DirectoryEntry.Bind()
     at System.DirectoryServices.DirectoryEntry.get_AdsObject()
     at System.DirectoryServices.PropertyValueCollection.PopulateList()
     at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
     at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
     at System.DirectoryServices.AccountManagement.ADUtils.RetriveWkDn(DirectoryEntry deBase, String defaultNamingContext, String serverN
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/1833337/active-directory-group-lookup-function-failing">Another report with this problem</a>.</p>
  
  <p>Any clues?</p>