Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebHostBuilder.Build() MissingMethodException in .NET Core migrated solution

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.

like image 732
oskarnrk Avatar asked Apr 06 '17 13:04

oskarnrk


2 Answers

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.

like image 57
Chrissx Avatar answered Oct 17 '22 15:10

Chrissx


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.

like image 22
ChrisBellew Avatar answered Oct 17 '22 16:10

ChrisBellew