Skip to content

'IServiceCollection' does not contain a definition for 'AddApiVersioning' #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
digibum opened this issue Jan 8, 2019 · 7 comments
Closed

Comments

@digibum
Copy link

digibum commented Jan 8, 2019

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?!

@commonsensesoftware
Copy link
Collaborator

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.

@digibum
Copy link
Author

digibum commented Jan 9, 2019

Awesome! Thank you for this info...

@OneGenkiGirl73
Copy link

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

@commonsensesoftware
Copy link
Collaborator

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

@OneGenkiGirl73
Copy link

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.

@commonsensesoftware
Copy link
Collaborator

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

@OneGenkiGirl73
Copy link

OneGenkiGirl73 commented Apr 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants