title: LINQ to XML error: Object reference not set to an instance of an object
body: <p>I am trying to grab some role information, the first node however does not have an element "projectRoleType" I want to skip over that one and only grab the ones that have a "projectRoleType" and "categoryId".  Every way I try to check I always get the error: Object reference not set to an instance of an object.  What am I not doing?</p>
  
  <pre><code>var _role = from r1 in loaded.Descendants("result")
                          let catid = (string)r1.Element("projectRoles").Element("projectRoleType").Element("categoryId")
                          where catid != null &amp;&amp; catid == categoryId
                          select new
                          {
                              id = (string)r1.Element("projectRoles").Element("projectRoleType").Element("id"),
                              name = (string)r1.Element("fullName"),
                              contactId = (string)r1.Element("contactId"),
                              role_nm = (string)r1.Element("projectRoles").Element("projectRoleType").Element("name")
                          };
              foreach (var r in _role)
              {
                  fields.Add(new IAProjectField(r.id, r.role_nm, r.name, r.contactId));
              }
  </code></pre>