title: C# LINQ object reference not set
body: <p>Considering the following code</p>
  
  <pre><code>IEnumerable&lt;String&gt; query = null;    
  query = from x in xml.Descendants(xmlMasterContainerName).Descendants(xmlElementName)
                      let guid = x.Attribute("guid") ?? new XAttribute("guid", "-1")
                      where x.Attribute(xmlAttributeIdName).Value == xmlAttributeIdValue
                      select guid.Value;
  </code></pre>
  
  <p>I get the 'object reference not set' when trying query.ToList()</p>
  
  <p>This is very probably caused by 'select guid.Value' when 'x.Attribute(xmlAttributeIdName).Value == xmlAttributeIdValue' does not exist.</p>
  
  <p>How can I check the where statement for existing value before selecting?
  Thanks</p>