title: Trying to bind XML to a ComboBox using WinForm and C#
body: <p>File Name: location.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;locations&gt;
    &lt;location id="1" position="Holiday" /&gt;
    &lt;location id="2" position="Time Off" /&gt;
    &lt;location id="3" position="Training" /&gt;
  &lt;/locations&gt;
  </code></pre>
  
  <p>I am trying to populate a combobox with the "text" from position. The id is not necessary at this time.</p>
  
  <p>My C# Code</p>
  
  <pre><code>        var obj = XDocument.Load("location.xml");            
          comboBox1.DisplayMember = "LocationPosition";
          comboBox1.ValueMember = "LocationID";
  
          comboBox1.DataSource = obj.Descendants("location").Select(x =&gt; new
          {
              LocationPosition = x.Attribute("name").Value,
              LocationID = x.Attribute("id").Value
          }).ToList(); // Crashing here
  </code></pre>
  
  <p>The Error message says</p>
  
  <pre><code>System.NullReferenceException was unhandled
    HResult=-2147467261
    Message=Object reference not set to an instance of an object.
    Source=CalendarSharing
    StackTrace:
  </code></pre>