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

This post was most recently updated on March 28th, 2023.

3 min read.

Whilst 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

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 of 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 relies 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 reason, 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

Okay – so the package won’t work. However, there are a couple of ways to work around this.

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 succeed, 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 the original publication, you need to download the package’s code yourself from the link below, as it hasn’t been published on nuget yet:

UPDATE: It took a while, but the GA version (and actually an additional minor release) is out! You can simply update your NuGet package to anything > 4.0, and you should be good!

For more background information about the issue, see this thread on GitHub:

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

mm
0 0 votes
Article Rating
Subscribe
Notify of
guest

5 Comments
most voted
newest oldest
Inline Feedbacks
View all comments