title: How to deserialize XML returned from REST API call?
body: <p>I am stuck deserializing the returned XML from a RESTful API call.
  This is the error message I am getting back:</p>
  
  <blockquote>
    <p>System.AggregateException : One or more errors occurred.   ---->
    System.Runtime.Serialization.SerializationException : Error in line 1
    position 106. Expecting element 'ArrayOfAPIUtility.PartInfo' from
    namespace
    '<a href="http://schemas.datacontract.org/2004/07/MyProject.Web" rel="nofollow noreferrer">http://schemas.datacontract.org/2004/07/MyProject.Web</a>'..
    Encountered 'Element'  with name 'Part', namespace ''.</p>
  </blockquote>
  
  <p>I followed <a href="https://stackoverflow.com/a/17459045/1405376">this stackoverflow</a> answer to create a successful REST connection.</p>
  
  <p>The returned XML looks like this:</p>
  
  <pre><code>&lt;Part&gt;
      &lt;ItemId&gt;12345&lt;/ItemId&gt;
      &lt;ItemDescription&gt;Item Description&lt;/ItemDescription&gt;
      &lt;Cost&gt;190.59&lt;/Cost&gt;
      &lt;Weight&gt;0.5&lt;/Weight&gt;
  &lt;/Part&gt;
  </code></pre>
  
  <p>I am trying to to deserialize it like this:</p>
  
  <pre><code>public class PartInfo
  {
      public string ItemId { get; set; }
      public string ItemDescription { get; set; }
      public string Cost { get; set; }
      public string Weight { get; set; }
  }
  
  public void GetPartInfo(string itemId)
  {
      var URL = ...some URL...;
      client.BaseAddress = new Uri(URL);
  
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
  
      HttpResponseMessage response = client.GetAsync(urlParameters).Result;
      if (response.IsSuccessStatusCode)
      {
          var dataObjects = response.Content.ReadAsAsync&lt;IEnumerable&lt;PartInfo&gt;&gt;().Result;
          foreach (var d in dataObjects)
          {
              Console.WriteLine("{0}", d.ItemId);
          }
      }
  }
  </code></pre>
  
  <p>The result is the error message pasted above.</p>
  
  <p>I think I am missing something very elementary here :-)</p>
  
  <p>Thank you very much for your help!</p>