7

I'm migrating a solution built with .NET Core SDK 1.0.0-preview2-1-003177 because I want to use it in Visual Studio 2017. I use the dotnet migrate command from .NET Core SDK 1.0.1, it goes well, it compiles. When I run the web part with IIS Express the classic Program.cs containing

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

host.Run();

crashes at Build() with this exception

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

I can't find the reason at all.

oskarnrk
  • 113
  • 1
  • 6

2 Answers2

5

It looks like some of your dependencies, not updated to the right version. It can be old version or new version. You can create a new project ( dotnet new ) and validate the packages version on your csproj file. 99% of the error cause by version mismatch.

Chrissx
  • 357
  • 1
  • 7
  • I thought this could be the reason, thanks for the confirmation. Copying and using the `.nuget/packages` folder from my colleague's PC the solution works, now the task is find what dependencies are wrong when I start in an empty environment. Can you explain how to do what you suggest (I'm new to VS, .NET & co)? Thank you very much. – oskarnrk Apr 10 '17 at 08:42
  • Sure :) If use installed .NET CLI tools latest version you can create new project with simple type dotnet new NAME and it will create a new project with clean csproj. If you are on windows you can easily use vs new project wizard to create the new project. After just copy the dependency part from that csproj to your current one. – Chrissx Apr 10 '17 at 13:49
  • 1
    I have jumped into the same problem, and have cross-checked my .csproj file with a new project, as suggested, without finding any mismatch. I also tried running the new (empty) project, and this did not throw the exception. Are there other things that could make this error appear? – Håkon Seljåsen May 23 '17 at 14:29
1

This happened for me because I was over eager and installed too many EntityFrameworkCore packages.

I had

Microsoft.EntityFrameworkCore 2.0.0-preview1-final
Microsoft.EntityFrameworkCore.SqlServer 1.1.2

I removed the first one so I was left with

Microsoft.EntityFrameworkCore.SqlServer 1.1.2

And then the error disappeared.

ChrisBellew
  • 1,144
  • 2
  • 12
  • 27