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=18.104.22.168, 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:
- How to recover the private key of a (.pfx) certificate? - January 20, 2021
- How to fix “System.IO.FileSystem: Could not find a part of the path \AppData\Local\AzureFunctionsTools\Releases\3.17.0\workers. Value cannot be null. (Parameter ‘provider’)” when running Azure Functions locally? - January 12, 2021
- How to nuke the Identity Cache in Visual Studio? - January 11, 2021