title: Web API: No MediaTypeFormatter is available to read an object of type 'IEnumerable`1' from content with media type 'text/plain'
body: <p>I get this error in my client (an ASP.NET MVC application) from a call to my ASP.NET Web API. I checked and the Web API is returning the data alright.</p>
  
  <pre><code>No MediaTypeFormatter is available to read an object of type 
  'IEnumerable`1' from content with media type 'text/plain'.
  </code></pre>
  
  <p>I believe that I can inherit from <code>DataContractSerializer</code> and implement my own serializer which can attach the <code>Content-Type</code> HTTP header as <code>text/xml</code>. </p>
  
  <p>But my question is: is that necessary?</p>
  
  <p>Because if it was, it would mean that the default <code>DataContractSerializer</code> does not set this essential header. I was wondering if Microsoft could leave such an important thing out. Is there another way out?</p>
  
  <p><strong>Here's the relevant client side code:</strong></p>
  
  <pre><code>public ActionResult Index()
          {
              HttpClient client = new HttpClient();
  
              var response = client.GetAsync("http://localhost:55333/api/bookreview/index").Result;
  
              if (response.IsSuccessStatusCode)
              {
                  IEnumerable&lt;BookReview&gt; reviews = response.Content.ReadAsAsync&lt;IEnumerable&lt;BookReview&gt;&gt;().Result;
                  return View(reviews);
              }
              else
              {
                  ModelState.AddModelError("", string.Format("Reason: {0}", response.ReasonPhrase));
                  return View();
              }
          }
  </code></pre>
  
  <p><strong>And here's the server side (Web API) code:</strong></p>
  
  <pre><code>public class BookReviewController : ApiController
      {
          [HttpGet]
          public IEnumerable&lt;BookReview&gt; Index()
          {
              try
              {
                  using (var context = new BookReviewEntities())
                  {
                      context.ContextOptions.ProxyCreationEnabled = false;
  
                      return context.BookReviews.Include("Book.Author");
                  }
              }
              catch (Exception ex)
              {
                  var responseMessage = new HttpResponseMessage
                  {
                      Content = new StringContent("Couldn't retrieve the list of book reviews."),
                      ReasonPhrase = ex.Message.Replace('\n', ' ')
                  };
  
                  throw new HttpResponseException(responseMessage);
              }
          }
      }
  </code></pre>