title: LINQ: Sequence contains no elements error
body: <p>I am trying to solve an error with using LINQ.
  I am pulling an XML node value using LINQ. The problem I am facing is when the node is not present in the XML I'm getting <code>Sequence contains no elements</code> error.
  I tried using DefaultIfEmpty, Singleordefault, and Firstordefault. 
  But then it throws a nullpointer exception. I guess I'm not above methods correctly.
  How can use one of these to solve the poblem?</p>
  
  <p>Here's the LINQ code that I'm using.</p>
  
  <pre><code>var costnode6 = doc.Root.Descendants(ns + "SERVICEUPGRADES").Single(c =&gt; (string)c.Element(ns + "DELIVERYTIME") == "before 3:30 PM").Element(ns + "TOTAL_COST");
          var cost6 = (decimal)costnode6;
  </code></pre>