title: Cannot serialise to XML in ASP.NET Core 2
body: <p>I'm very confused at the moment with a basic ASP.NET Core 2 API project and content negotiation and returning something other than JSON. </p>
  
  <p>I've had this working before in a 1.1 project but not in a 2. I basically want to return something either as JSON or XML depending on request type.</p>
  
  <p>As part of that requirement I set up the XML formatter like so:</p>
  
  <pre><code>    public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc(options =&gt;
          {
              options.ReturnHttpNotAcceptable = true;
              options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
          });
      }
  </code></pre>
  
  <p>I could also use <code>AddXmlSerializerFormatters()</code> but same difference (and tried). This is the way I've seen in countless examples and done before.</p>
  
  <p>I have a single controller and single action, basically looks like:</p>
  
  <pre><code>[Route("api/[controller]")]
  public class DefaultController : Controller
  {
      [HttpGet]
      [Route("")]
      public IActionResult Index()
      {
          return Ok(new
          {
              success = true
          });
      }
  }
  </code></pre>
  
  <p>Now when I run I get this back in Postman:</p>
  
  <pre><code>{"success": true}
  </code></pre>
  
  <p>So it works (or at least defaults) to JSON.</p>
  
  <p>Then if I request using the header <code>Accept: application/xml</code> instead I now get a HTTP error of 406.</p>
  
  <p>If I take off <code>options.ReturnHttpNotAcceptable = true;</code>, it will return JSON regardless.</p>
  
  <p>What am I missing? I'm sat scratching my head on this. As far as I know I've registered an acceptable content formatter.</p>