title: Adding contact to distribution list: The Principal object must have a valid SID IdentityType in order to perform this operation
body: <p>I am trying to add a <code>Contact</code> to a distribution list. </p>
  
  <p>Here is how I am going about it:</p>
  
  <pre><code>public void AddContactsToGroup(string groupName, string[] userNames)
  {
           using (PrincipalContext context = GetPrincipalContext())
           {
              var group = GroupPrincipal.FindByIdentity(context, IdentityType.Name, groupName);
  
              if (group.IsSecurityGroup.HasValue &amp;&amp; group.IsSecurityGroup.Value == true)
                 throw new ArgumentException("Groups cannot be security groups.");
  
              foreach (var userName in userNames)
              {
                 var query = new ContactPrincipal(context)
                                {
                                   Name = userName
                                };
  
                 var user = Search(query).First();
  
                 group.Members.Add(user);
              }
  
              group.Save(context);
           }
        }
  
    private List&lt;T&gt; Search&lt;T&gt;(T query) where T : Principal
    {
       var searcher = new PrincipalSearcher();
       searcher.QueryFilter = query;
       PrincipalSearchResult&lt;Principal&gt; results = searcher.FindAll();
  
       return results.Cast&lt;T&gt;().ToList();
    }
  </code></pre>
  
  <p>Here is the <code>ContactPrincipal</code> class (I borrowed this from somewhere):</p>
  
  <pre><code>   [DirectoryObjectClass("contact")]
     [DirectoryRdnPrefix("CN")]
     public class ContactPrincipal : AuthenticablePrincipal
     {
        public ContactPrincipal(PrincipalContext context)
           : base(context)
        {
        }
  
        public static ContactPrincipal FindByIdentity(PrincipalContext context, string identityValue)
        {
           return (ContactPrincipal) Principal.FindByIdentityWithType(context, typeof (ContactPrincipal), identityValue);
        }
  
        public static ContactPrincipal FindByIdentity(PrincipalContext context, IdentityType identityType,
                                                      string identityValue)
        {
           return
              (ContactPrincipal)
              Principal.FindByIdentityWithType(context, typeof (ContactPrincipal), identityType, identityValue);
        }
  
        [DirectoryProperty("mail")]
        public string EmailAddress
        {
           get
           {
              if (ExtensionGet("mail").Length == 1)
              {
                 return ExtensionGet("mail")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("mail", value); }
        }
  
        [DirectoryProperty("givenName")]
        public string GivenName
        {
           get
           {
              if (ExtensionGet("givenName").Length == 1)
              {
                 return ExtensionGet("givenName")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("givenName", value); }
        }
  
        [DirectoryProperty("middleName")]
        public string MiddleName
        {
           get
           {
              if (ExtensionGet("middleName").Length == 1)
              {
                 return ExtensionGet("middleName")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("middleName", value); }
        }
  
        [DirectoryProperty("sn")]
        public string Surname
        {
           get
           {
              if (ExtensionGet("sn").Length == 1)
              {
                 return ExtensionGet("sn")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("sn", value); }
        }
  
        [DirectoryProperty("mobile")]
        public string MobileTelephoneNumber
        {
           get
           {
              if (ExtensionGet("mobile").Length == 1)
              {
                 return ExtensionGet("mobile")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("mobile", value); }
        }
  
        [DirectoryProperty("telephoneNumber")]
        public string VoiceTelephoneNumber
        {
           get
           {
              if (ExtensionGet("telephoneNumber").Length == 1)
              {
                 return ExtensionGet("telephoneNumber")[0].ToString();
              }
              else
              {
                 return null;
              }
           }
           set { ExtensionSet("telephoneNumber", value); }
        }
     }
  </code></pre>
  
  <p>My problem is, when I hit the </p>
  
  <pre><code>group.Members.Add(user) 
  </code></pre>
  
  <p>line in the <code>AddContactsToGroup</code> method, an error is thrown that states </p>
  
  <blockquote>
    <p><em>The Principal object must have a valid SID IdentityType in order to perform this operation.</em> </p>
  </blockquote>
  
  <p>When I interrogate the properties of the <code>ContactPrincipal</code>, the <code>Sid</code> is, in fact null. This isn't surprising since a <code>Contact</code> is an object with no security. </p>
  
  <p>How can I add a <code>Contact</code> to a non-security group?</p>