簡體   English   中英

找不到方法:'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider'

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

在我的 .net 核心應用程序的主要方法中,我收到了這個錯誤,我不知道我應該在哪里尋找解決方案。

這是我的主要方法:

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

        host.Run();
    }

這是我在按 F5 啟動項目時收到的錯誤消息:

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

對於 .NET Core 3.1,出於某種原因,Visual Studio 沒有提示我需要using Microsoft.Extensions.DependencyInjection; . 手動添加它為我修復了它。

解決了將ApplicationInsights軟件包從2.0降級到1.1.2版本的問題

我剛剛使用aspnet core 2.0遇到了這個問題,在我的情況下,將其他默認軟件包(AspNetCore,AspNetCore.Mvc,NetCore.App)升級到2.0可以解決問題,盡管安裝了2.0軟件包(除App Insights之外)最初為1.1.x

使用Sql nuget並進行升級時,我遇到了類似的問題。

IDbContextFactory必須更改為IDesignTimeDbContextFactory

如果您使用 Microsoft.AspNet.OData,則從 NuGet 版本 7.5.15 及更高版本開始出現此錯誤。 降級到 7.5.14 可能會解決此問題。

我在 Microsoft.AspNet.OData 版本 7.5.17 中也遇到了這個錯誤,降級到 7.5.14 解決了這個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM