title: Active directory cross domain - group members using PrincipalContext
body: <p>I am trying to fetch the members of a given active directory group by using DirectoryServices.AccouneManagement namespaces classes in c#.</p>
  
  <p>If I have my principal context object constructor specified for a specific domain, then whenever I access the member from the the group which is from the other domains I am running into the below error:
  "A referral was returned from the server".</p>
  
  <p>Scenario is : I have different sub domains under root domain 
  Eg: emea.mycorp.com, asia.mycorp.com, asiapacific.mycorp.com, xyz.mycorp.com</p>
  
  <p>If i am running the below code from the domain xyz.mycorp.com, for a group in asiapacific If I specify the servername in the principal context object I could access the group.</p>
  
  <pre><code>private PrincipalContext context = 
      new PrincipalContext(ContextType.Domain, "asiapacific domain server name");
  </code></pre>
  
  <p>If my group has the users from other domains like emea\abcd, the below code fails at UserPrincipal:</p>
  
  <pre><code>GroupPrincipal SearchGroup = GroupPrincipal.FindByIdentity(context, "Dev Team"); 
      GroupName = new List&lt;string&gt;();
      foreach (UserPrincipal p in SearchGroup.GetMembers())      
      {        
          GroupName.Add(p.SamAccountName + " " + p.DistinguishedName + " " + p.Name);  
      }
  </code></pre>
  
  <p>So, Is there a way that I can pass the context for the root domain, so that the code will work irrespective of the domain to which the user belongs to. I tried below and with none of it with luck:</p>
  
  <pre><code>private PrincipalContext context = 
      new PrincipalContext(ContextType.Domain, "mycorp.com");
  </code></pre>
  
  <p>or</p>
  
  <pre><code>private PrincipalContext context = 
      new PrincipalContext(ContextType.Domain, "DC=mycorp,DC=com");
  </code></pre>