title: NullReferenceException C#
body: <p>I have a problem with my XML Reading file.</p>
  
  <pre><code>XDocument xdoc;
          if (customStyle)
          {
             xdoc = XDocument.Load(@"E:\test-doc.xml");
          }
          else
          {
             xdoc = XDocument.Load(@"E:\ieee-doc.xml");
          }
  
          Dictionary&lt;string, FormatStyles&gt; customeStylesDic = new Dictionary&lt;string, FormatStyles&gt;();
  
          xdoc.Descendants("Title").Select(t =&gt; new
          {
  
              fontType = t.Element("fontType").Value,
  
              fontSize = t.Element("fontSize").Value,
  
              Underline = t.Element("Underline").Value,
  
              Bold = t.Element("Bold").Value,
  
              Italic = t.Element("Italic").Value,
  
              Alignment = t.Element("Alignment").Value,
          }).ToList().ForEach(t =&gt;
          {
              FormatStyles formatStyle = new FormatStyles();
              string style = "Title";
              formatStyle.CustomFontType = t.fontType;
              formatStyle.CustomFontSize = t.fontSize;
              formatStyle.CustomisBold = Convert.ToBoolean(t.Bold);
              formatStyle.CustomisItalic = Convert.ToBoolean(t.Italic);
              formatStyle.CutomisUnderline = Convert.ToBoolean(t.Underline);
              formatStyle.Cutomalignment = t.Alignment;
  
  
              customeStylesDic.Add(style, formatStyle);
  
  
          });
  </code></pre>
  
  <p>Here I try to read XML file using LINQ and pass this values to FormatStyles class, It gives NullReferenceException. But I can't find the error. Can any one help me..</p>
  
  <p>This is my XML file</p>
  
  <pre><code>    &lt;Styles&gt;
      &lt;Title&gt;
      &lt;fontType&gt;Times New Roman&lt;/fontType&gt; 
      &lt;fontSize&gt;20&lt;/fontSize&gt; 
      &lt;Bold&gt;true&lt;/Bold&gt; 
      &lt;Underline&gt;false&lt;/Underline&gt; 
      &lt;Italic&gt;true&lt;/Italic&gt; 
      &lt;Alingment&gt;center&lt;/Alingment&gt; 
      &lt;/Title&gt;
      &lt;/Styles&gt;
  </code></pre>