title: Linq query "Object reference not set to an instance of an object"
body: <p>I have 2 simple webservice methods that query an XML document (stored in HTTP cache) that I am querying via javascript. The <code>GetCitiesForAffiliate()</code> method is throwing a NullReferenceException on the "select new" line when I pass in one perfectly valid item of data for the aff parameter. It works fine for other data in the aff parameter. The other method also works fine, even with the same aff parameter that causes the other method to bomb out.</p>
  
  <p>I just validated the XML that I am querying. Both methods just return an empty json string when I pass in an aff that doesn't exist, which is OK. What should I look at that might be wrong? </p>
  
  <pre><code>    [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public string GetCitiesForAffiliate(string aff)
      {
          LocationService loc = new LocationService();
          var query = (from center in loc.centersXml.Descendants("Center")
                       where center.Element("ServiceArea").Value.Equals(aff)
                       select new {
                           City = center.Element("City").Value
                       }).Distinct().OrderBy(x =&gt; x.City);
  
          JavaScriptSerializer serializer = new JavaScriptSerializer();
          string json = serializer.Serialize(query);
  
          return json;
      }
  
      [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
      public string GetCentersForAffiliateCity(string aff, string city)
      {
          LocationService loc = new LocationService();
          var query = (from center in loc.centersXml.Descendants("Center")
                       where center.Element("ServiceArea").Value.Equals(aff) &amp;&amp; center.Element("City").Value.Equals(city)
                       select new { 
                           ID = center.Element("ID").Value,
                           Name = center.Element("Name").Value 
                       }).Distinct().OrderBy(x =&gt; x.Name);
  
          JavaScriptSerializer serializer = new JavaScriptSerializer();
          string json = serializer.Serialize(query);
  
          return json;
      }
  </code></pre>