GitHub thread about the error - and long and winding discussion about the topic.

How to resolve build failing with .NET Core 3 and Microsoft.AspNetCore.Mvc.Versioning

Reading Time: 3 minutes.

Building a proof-of-concept on .NET Core 3.0 preview 7 I ran into issues when developing web APIs. This release is production-ready (according to Microsoft -see below), but every now and then you run into really unintuitive and sometimes surprising issues.

Go Live
NET Core 3.0 Preview 7 is supported by Microsoft and can be used in production. We strongly recommend that you test your app running on Preview 7 before deploying Preview 7 into production. If you find an issue with .NET Core 3.0, please file a GitHub issue and/or contact Microsoft support.

https://devblogs.microsoft.com/dotnet/announcing-net-core-3-0-preview-7/

I was trying to add a reference to Microsoft.AspNetCore.Mvc.Versioning to configure versioning for my APIs. That’s when I ran into issues.

Problem

Table of Contents

The error pops up when you’re building your solution, and causes the build to fail. The error is shown below:

Method 'ApplyAsync' in type 'Microsoft.AspNetCore.Mvc.Routing.ApiVersionMatcherPolicy' from assembly 'Microsoft.AspNetCore.Mvc.Versioning, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

The error message didn’t really give me a clear indication on how to change my code – but luckily the fix was simple. Unfortunate, but simple.

Error

A similar error can likely be caused by other reasons as well, but this particular issue was due to the implementation of Microsoft.AspNetCore.Mvc.Versioning relying on a lot of classes having public accessors. They used to, in 2.0, but in 3.0, they don’t.

This causes the package to be incompatible with .NET Core 3.0.

In fact, the package’s author explained on GitHub, that as of now the package is not supposed to work with .NET Core 3.0 at all. For whatever reasons, NuGet will let you install it, even though it shouldn’t. See the quote below:

ASP.NET Core 3.0 is not supported – yet. The API Versioning package declares Microsoft.AspNetCore.Mvc.Core (>= 2.2.0 && < 3.0.0) so I’m not sure how you able to bypass the NuGet constraints. Regardless, I rarely provide support for prereleases. As a one-man army, I just don’t have the capacity to support a moving target. Furthermore, there hasn’t been any demand to support 3.0. It will be supported when it’s officially released, but until then, all my focus is on existing issues.

Commonsensesoftware on GitHub

However, there’s a couple of options you have.

Solution

First of all, let’s start with the simple solution: You just remove the offending package(s). In this case, Microsoft.AspNetCore.Mvc.Versioning.

So, head out to your NuGet package manager, find the package, and if it is anything under 4.0.0, hit “Uninstall”.

How to uninstall Microsoft.AspNetCore.Mvc.Versioning NuGet package.
How to uninstall Microsoft.AspNetCore.Mvc.Versioning NuGet package.

Now, it’s easy to see that this is not a real solution for a lot of reasons. It might get your builds back to succeeding, so if you don’t really need the versioning right now, you might be good.

However, a lot of you will want to have it. So, consider the below solutions instead:

This package is receiving an update that’ll make it compatible with .NET Core 3.0 once again. The compatible version is Microsoft.AspNetCore.Mvc.Versioning 4.0 preview 8. If you’re reading this soon after original publish, you need to download the package’s code yourself from the link below, as it hasn’t been published on nuget yet:

https://github.com/microsoft/aspnet-api-versioning/releases/tag/4.0.0.preview8.19369.1

If you’re reading this a bit later (right now I’m guessing the end of August 2019), the GA version of Microsoft.AspNetCore.Mvc.Versioning 4.0 might be out already – and available on NuGet. In that case, just grab/update the package from there, and you should be good!

For more information, see this thread on GitHub:

https://github.com/microsoft/aspnet-api-versioning/issues/499

Antti K. Koskela

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world.

He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.

This is his personal professional (e.g. professional, but definitely personal) blog.
mm

Leave a Reply

avatar
5000
  Subscribe  
Notify of