Search code examples
c#asp.net.net-coredotnet-cli

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.


Solution

  • 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.