Aspnet-api-versioning: 'IServiceCollection' does not contain a definition for 'AddApiVersioning'

Created on 8 Jan 2019  Â·  7Comments  Â·  Source: microsoft/aspnet-api-versioning

I tried to add ApiVersioning in ConfigureServices() method but got an error:
'IServiceCollection' does not contain a definition for 'AddApiVersioning' and no accessible extension method 'AddApiVersioning' accepting a first argument of type 'IServiceCollection' could be found...

Tried to install package Microsoft.AspNetCore.Mvc.Versioning 3.1.1 get new error:

Version conflict detected for Microsoft.AspNetCore.Authentication.Abstractions. Install/reference Microsoft.AspNetCore.Authentication.Abstractions 2.2.0 directly to project TM.DataCollector to resolve this issue. 
 TM.DataCollector -> Microsoft.AspNetCore.Mvc.Versioning 3.1.1 -> Microsoft.AspNetCore.Mvc.Core 2.2.0 -> Microsoft.AspNetCore.Authorization.Policy 2.2.0 -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0) 
 TM.DataCollector -> Microsoft.AspNetCore.App 2.1.1 -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.1.1 && < 2.2.0).  TM.DataCollector    C:\Users\Matej\Dropbox (HSI)\Development\InproTelemetrija\TM v.2\Solutions\TM.DataCollector\TM.DataCollector.csproj 1   

Using .Net Core 2.1.1
What am i missing?!

asp.net core question

Most helpful comment

You won't be able to use 3.1+ on ASP.NET Core 2.1 as it specifically targets 2.2. You probalby want to go back to 3.0. The only real difference between 3.0 and 3.1 is that 3.0 still targets 2.0, which allows you to use any version of ASP.NET Core 2.0+. 3.1 adds support for the _Endpoint Routing_ feature in ASP.NET Core 2.2. To use this feature, you obviously need to use 2.2+.

The two easily solutions are:

  1. Go back to API Versioning 3.0 (if you don't need _Endpoint Routing_, the features are the same as 3.1)
  2. Update ASP.NET Core to 2.2

I hope that helps.

All 7 comments

You won't be able to use 3.1+ on ASP.NET Core 2.1 as it specifically targets 2.2. You probalby want to go back to 3.0. The only real difference between 3.0 and 3.1 is that 3.0 still targets 2.0, which allows you to use any version of ASP.NET Core 2.0+. 3.1 adds support for the _Endpoint Routing_ feature in ASP.NET Core 2.2. To use this feature, you obviously need to use 2.2+.

The two easily solutions are:

  1. Go back to API Versioning 3.0 (if you don't need _Endpoint Routing_, the features are the same as 3.1)
  2. Update ASP.NET Core to 2.2

I hope that helps.

Awesome! Thank you for this info...

Console Application / Service - serviceProvider fails to get GetService this afternoon.

Works perfectly in another console application with the exact same code in it...wonder why ? :-P

@OneGenkiGirl73 Which service are you requesting? Is there something else about your configuration you can share?

There was nothing special about it, just a simple "controller" I called an ISiteController that does CRUD for a datatable. In the console application on my home computer it works perfectly.

I would think the serviceProvider.GetService would work just the same, because the code is literally an exact replica of the working code in the other console application.

Sounds like something else is awry. Are you saying if you remove the call to services.AddApiVersioning(), then things work as normal?

I'm sorry, I meant to say the .GetService isn't working as it does with the other database controller I built on my other dev machine. I'm just wondering why the behavior would be different on the other machine with the exact same code...?

Sent from Yahoo Mail on Android

On Wed, Apr 15, 2020 at 9:39 PM, Chris Martineznotifications@github.com wrote:

Sounds like something else is awry. Are you saying if you remove the call to services.AddApiVersioning(), then things work as normal?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Was this page helpful?
0 / 5 - 0 ratings