3

I'm trying to figure out how ASP.NET 5 Web API supports Content Negotiation. In order to support XML (in addition to the default JSON support), according to another answer here on Stack Overflow, I need to add that support from an optional NuGet package.

Things have changed a bit since that answer, but I pulled down the Microsoft.AspNet.Mvc.Xml package and edited my Startup.cs file:

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc().AddMvcOptions(options =>
    {
        options.InputFormatters.Add(new XmlSerializerInputFormatter());
    });
}

This, however, doesn't compile:

The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.

Here are the full compilation error messages:

1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,17,33,44): DNX 4.5.1 error CS0012: The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,45,33,78): DNX 4.5.1 error CS1503: Argument 1: cannot convert from 'Microsoft.AspNet.Mvc.Xml.XmlSerializerInputFormatter' to 'Microsoft.AspNet.Mvc.Formatters.IInputFormatter'
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,17,33,44): DNX Core 5.0 error CS0012: The type 'InputFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNet.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Users\mark\Desktop\WebApplication1\src\WebApplication1\Startup.cs(33,45,33,78): DNX Core 5.0 error CS1503: Argument 1: cannot convert from 'Microsoft.AspNet.Mvc.Xml.XmlSerializerInputFormatter' to 'Microsoft.AspNet.Mvc.Formatters.IInputFormatter'

The error message seems fairly clear, but the project already includes Microsoft.AspNet.Mvc.Core, although not quite in the desired version:

Id                                  Versions         
--                                  --------         
Microsoft.AspNet.IISPlatformHandler {1.0.0-rc1-final}
Microsoft.AspNet.Mvc                {6.0.0-rc1-final}
Microsoft.AspNet.Mvc.Core           {6.0.0-rc1-final}
Microsoft.AspNet.Mvc.Xml            {6.0.0-beta5}    
Microsoft.AspNet.Server.Kestrel     {1.0.0-rc1-final}
Microsoft.AspNet.StaticFiles        {1.0.0-rc1-final}
Microsoft.Extensions.Configurati... {1.0.0-rc1-final}
Microsoft.Extensions.Configurati... {1.0.0-rc1-final}
Microsoft.Extensions.Logging        {1.0.0-rc1-final}
Microsoft.Extensions.Logging.Con... {1.0.0-rc1-final}
Microsoft.Extensions.Logging.Debug  {1.0.0-rc1-final}

As I'm writing this, ASP.NET 5 is only available in a Release Candidate version, so the above packages are the most recent available.

Clearly, Microsoft.AspNet.Mvc.Core 6.0.0.0 isn't available. In a normal .NET project, I'd attempt to solve this issue with a binding redirect, but since this is ASP.NET 5, that's apparently no longer the way to do things.

How can I make my code compile?

1 Answer 1

7

I believe you have to use the Microsoft.AspNet.Mvc.Formatters.Xml package instead. Also see this issue on github.

Also a hot tip: Use http://packagesearch.azurewebsites.net/ to search for which NuGet-package contains the class you are looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

That pacakgesearch website is fabulous - I've been looking for something like that for ages!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.