Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my Main method of .net Core app Iam getting this error and I dunno where should I look for solution.

this is my main method:

 public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseApplicationInsights()
            .Build();

        host.Run();
    }

This is error message I am getting when hit F5 to fire project:

System.MissingMethodException: 'Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.'
like image 451
Daniel Rusnok Avatar asked Jul 10 '17 06:07

Daniel Rusnok


People also ask

What is BuildServiceProvider?

BuildServiceProvider(IServiceCollection, ServiceProviderOptions) Creates a ServiceProvider containing services from the provided IServiceCollection optionally enabling service-creation and scope validation.

What is IServiceProvider .NET core?

The IServiceProvider is responsible for resolving instances of types at runtime, as required by the application. These instances can be injected into other services resolved from the same dependency injection container. The ServiceProvider ensures that resolved services live for the expected lifetime.


2 Answers

I've just come across this issue using aspnet core 2.0, in my case upgrading the other default packages (AspNetCore, AspNetCore.Mvc, NetCore.App) to 2.0 did the trick, despite installing 2.0 the packages (apart from App insights) were 1.1.x initially

like image 119
Rik Clews Avatar answered Nov 09 '22 18:11

Rik Clews


For .NET Core 3.1, for some reason Visual Studio wasn't giving me the hint that I need to add using Microsoft.Extensions.DependencyInjection;. Manually adding that fixed it for me.

like image 43
Neurion Avatar answered Nov 09 '22 16:11

Neurion