This post was most recently updated on January 17th, 2020.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.
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.
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.
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=220.127.116.11, 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.
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
Okay – so the package won’t work. However, there’s a couple of ways to work around this.
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”.
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:
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:
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. He's also Microsoft MVP for Office Development.
This is his personal professional (e.g. professional, but definitely personal) blog.
Latest posts by Antti K. Koskela (see all)
- WordPress media uploads failing after year/month change? Easy fix :) - January 14, 2020
- App Service refuses connections with error: “No connection could be made because the target machine actively refused it” - January 9, 2020
- 2019 – Year Review (200th post on this blog!) - December 31, 2019