title: Object reference not set to an instance of an object using LINQ C#
body: <p>I solved the namespace problem but I still have error message. I think the problem is with getting informations into list</p>
  
  <pre><code>IEnumerable&lt;XElement&gt; InvoiceLines = from e in Document.Root
                                          .Element(P + "InvoiceLines")
                                          .Elements(P + "InvoiceLine")
                          select new XElement("InvoiceLine",
                      new XAttribute("LineNumber", e.Element(P + "ID").Value),
                      new XAttribute("ProductName", e.Element(P + "Item").Attribute(P + "Description").Value),
                      new XAttribute("UnitPriceTaxInclusive", e.Element(P + "UnitPriceTaxInclusive").Value),
                      new XAttribute("Quantity", e.Element(P + "InvoicedQuantity").Value),
                      new XAttribute("UnitCode", e.Element(P + "InvoicedQuantity").Attribute(P + "@unitCode").Value));  
  </code></pre>
  
  <p>then I try to save the document using this InvoiceLines, like this:</p>
  
  <pre><code>XDocument FinalDocument = new XDocument( 
              new XElement("Invoice",
              new XAttribute("BuyerName", BuyerName),
              new XAttribute("SellerName", SellerName),
              new XAttribute("IssueDate", IssueDate),
              new XAttribute("ID", InvoiceID),
              new XElement("InvoiceLines", InvoiceLines)
              ));
          FinalDocument.Save(name);
          FinalDocument.Save(Console.Out);
  </code></pre>
  
  <p>error tells me that the problem is int the line "select new XElement..." in InvoiceLines </p>