efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Method not found: Microsoft.Extensions.DependencyInjection.IServiceCollection

Open im1dermike opened this issue 9 years ago • 29 comments

From issue #8426, I ended up upgrading EFCore versions. I ran the following package manager commands in my web and DAL projects:

install-package Microsoft.EntityFrameworkCore.SqlServer -Pre -Version 2.0.0-preview1-final
install-package Microsoft.EntityFrameworkCore -Pre -Version 2.0.0-preview1-final

I then went to run my web application and got the following exception in the Program.cs file when it tries to execute

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>()
    .Build();

Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.

I'm assuming the upgrade has broken something in my Startup class in my web app.

im1dermike avatar May 17 '17 12:05 im1dermike

You need to upgrade all your packages from Asp.net core and not just the EF ones.

smitpatel avatar May 17 '17 21:05 smitpatel

@ajcvickers i am getting this error very frequently, because of package dependencies. Project A references a package that uses v1 of package B. in other project some other package is using version 2 of B which results into this situation. and detecting which package is causing problem is some how impossible in large project. any idea?

HassanHashemi avatar Jun 06 '17 17:06 HassanHashemi

I had this problem after I upgraded Microsoft.Extensions.DependencyInjection.Abstractions to version 2.0.0 then reverted back... Since the assembly is still on the hard drive it is still detected and loaded. The solution was to delete the bin folder and build a gain.

assilsicom avatar Jul 15 '17 23:07 assilsicom

Ditto what @assilsicom said. I also reverted back to Core 1.1 from 2.0 and was getting this error. Deleting the bin folders worked as stated above and resolved the issue.

elmojo avatar Aug 17 '17 17:08 elmojo

I have a .NET Standard 1.4 library that has Microsoft.EntityFrameworkCore.Sqlite 1.1.2 dependency There is a UWP project that references it and it works fine There is a .NET Core 2.0 project that references it and it gets this error

Please stop closing valid issues, this issue still exists

barishamil avatar Aug 24 '17 11:08 barishamil

Reopening so that we can write a proper response here. Using 1.x & 2.x packages of Asp.net in same project is not supported.

smitpatel avatar Aug 24 '17 21:08 smitpatel

running into same issue here, except I am using a service fabric stateless webapp, I read SF isn't compatible with AspNetCore 2.0 yet. Do i have to roll back because everything seems to be interdependent and a massive breaking change

ConX-Ryan avatar Aug 25 '17 01:08 ConX-Ryan

I'm also running into this issue. The moment i hit "services.AddIdentityServer()" i'm getting the error.

JKeetman avatar Aug 31 '17 08:08 JKeetman

Having the same issues as @JKeetman , Just updated to to .NET Core 2.0 and IdentityServer4-preview4

Shawn960 avatar Sep 04 '17 07:09 Shawn960

You need to update to ASP.NET Core 2.0. Anything that called BuildServiceProvider needs to be updated.

davidfowl avatar Sep 04 '17 07:09 davidfowl

Same issue here. I've updated everything to 2.0. Also updated IdenetyServer 4 to 2.0.0-preview2. Any suggestions?

shauliz avatar Sep 11 '17 11:09 shauliz

Same Error with ASP.NET Core 2.0 and IdenetyServer4 1.5.2

gato-negro avatar Sep 11 '17 21:09 gato-negro

@gato-negro - IdentityServer4 1.5.2 uses ASP.NET core 1.1.x packages. 1.x to 2.0 is breaking change hence ASP.NET core 2.0 is not compatible with IdentityServer 1.5.2. You would need at least IdentityServer4 2.0.0-preview3 packages to use with ASP.NET Core 2.0

smitpatel avatar Sep 11 '17 22:09 smitpatel

@smitpatel You are right. I updated all identityserver4 related packages to 2.0.0-rc1 and now it works as expected. Thanks

gato-negro avatar Sep 12 '17 07:09 gato-negro

what if we have a library that Called BuildServiceProvider ? what Should replace it?

jstacoder avatar Oct 17 '17 20:10 jstacoder

what if we have a library that Called BuildServiceProvider ? what Should replace it?

The library needs to be updated.

davidfowl avatar Oct 18 '17 21:10 davidfowl

Ok, let's say I am the one responsible to do that, and I know where in my code base we are calling it, what would I need to change it to, to work now? Or where can I go that will help me figure that out? Because I'm almost positive that the library won't officially be updated anytime soon.

jstacoder avatar Oct 19 '17 20:10 jstacoder

The library just needs to reference the new version of Microsoft.Extensions.DependencyInjection (the 2.0.0 version).

davidfowl avatar Oct 20 '17 06:10 davidfowl

Ahh perfect, thank you

jstacoder avatar Oct 20 '17 07:10 jstacoder

Just curious as to how the dependency tree is allowed to get into an incompatible scenario like this - is there something more that can be done via semver and nuspec versioning constraints on packages to prevent this kind of thing from happening?

dazinator avatar Nov 08 '17 15:11 dazinator