本文介绍了从2.0.0-preview1-final升级到2.0.0-preview2-final之后的System.MissingMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的视觉工作室更新为Preview 4,并将所有软件包从Core 2.0 Preview 1 Final更新为Core 2.0 Preview 2 Final。以下是我的 csproj 文件,全部升级后。

 < ItemGroup> 
< PackageReference Include = HtmlAgilityPack版本= 1.5.2-beta2 />
< PackageReference Include = Humanizer.Core Version = 2.2.0 />
< PackageReference Include = Microsoft.AspNetCore Version = 2.0.0-preview2-final />
< PackageReference Include = Microsoft.AspNetCore.Mvc Version = 2.0.0-preview2-final />
< PackageReference Include = Microsoft.EntityFrameworkCore.Design Version = 2.0.0-preview2-final />
< PackageReference Include = Microsoft.Extensions.Logging.Debug Version = 2.0.0-preview2-final />
< PackageReference Include = Npgsql.EntityFrameworkCore.PostgreSQL Version = 2.0.0-preview2-final />
< PackageReference Include = Serilog.Enrichers.Environment Version = 2.1.2 />
< PackageReference Include = Serilog.Extensions.Logging Version = 2.0.0-dev-10164 />
< PackageReference Include = Serilog.Settings.Configuration Version = 2.4.0 />
< PackageReference Include = Serilog.Sinks.Literate Version = 3.0.1-dev-00044 />
< PackageReference Include = Swashbuckle.AspNetCore Version = 1.0.0 />
< PackageReference Include = AutoMapper Version = 6.1.1 />
< PackageReference Include = Microsoft.AspNetCore.Authentication.JwtBearer Version = 2.0.0-preview2-final />
< PackageReference Include = Microsoft.AspNetCore.Identity.EntityFrameworkCore Version = 2.0.0-preview2-final />
< / ItemGroup>

< ItemGroup>
< DotNetCliToolReference Include = Microsoft.EntityFrameworkCore.Tools.DotNet Version = 2.0.0-preview2-final />
< / ItemGroup>

以下是原始异常详细信息。

  System.MissingMethodException:找不到方法: Microsoft.Extensions.Configuration.IConfiguration Microsoft.Extensions.Logging.LoggerFactory.get_Configuration()。 
在Microsoft.AspNetCore.ApplicationInsights.HostingStartup.ApplicationInsightsLoggerStartupFilter。<> c__DisplayClass0_1。< Configure> b__0(IApplicationBuilder构建器)Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter。<> _0.c ;在Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()上配置> b__0(IApplicationBuilder应用)

Program.cs

 使用Microsoft.AspNetCore.Builder; 
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.Extensions.Logging;
使用System.IO;

名称空间Phoenix
{
公共类AppProgram
{
public static void Main(string [] args)
{
var host = new WebHostBuilder()
.ConfigureLogging(factory =>
{
factory.AddConsole();
factory.AddDebug();
})
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup< Startup>()
.Build();

host.Run();
}
}
}

Startup.cs(我曾经注释掉 loggerFactory.AddSeriLog()调用,因为它在我更新所有软件包后立即生成错误。

  public void ConfigureServices(IServiceCollection服务)
{
services.AddMvc();

services.AddSwaggerGen(c =>
{
//为简洁起见删除了
});

//为简洁起见删除了DI语句

Log.Logger = new LoggerConfiguration ()
.ReadFrom.Configuration(Configuration)
.CreateLogger();
}

public void Configure(IApplicationBuilder应用,IHostingEnvironment env,ILoggerFactory loggerFactory)
{
//loggerFactory.AddSerilog();

app.UseMvc();

app.UseSwagger();

app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint( / swagger / v1 / swagger.json,我的API V1);
});

}

如 loggerFactory.AddSerilog(); ,我尝试在 ConfigureServices services.AddSeriLog() c>方法。



我也尝试安装软件包 Microsoft.Extensions.Logging ,也没有解决。 / p>

我还尝试从新模板中替换 Program.cs 文件的内容,如下所示。

  public class Program 
{
public static void Main(string [ ] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string [] args)=>
WebHost.CreateDefaultBuilder(args)
.UseStartup< Startup>()
.Build();
}

有人可以帮我解决此问题吗?



更新



添加软件包 Microsoft.AspNetCore.All 解决了此问题。但是我真的不想添加此软件包,因为这会将许多不需要的引用添加到该单个软件包中。

解决方案

必需的软件包是



Microsoft.Extensions.Logging.Configuration



我添加了解决该问题的软件包。

 < PackageReference Include = Microsoft.Extensions.Logging.Configuration Version = 2.0.0-preview2-final /> 


I just updated my visual studio to preview 4 and updated all my packages from Core 2.0 Preview 1 Final to Core 2.0 Preview 2 Final. Below is my csproj file after all upgradation.

<ItemGroup>
    <PackageReference Include="HtmlAgilityPack" Version="1.5.2-beta2" />
    <PackageReference Include="Humanizer.Core" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-preview2-final" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0-preview2-final" />
    <PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.2" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.0-dev-10164" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="2.4.0" />
    <PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
    <PackageReference Include="AutoMapper" Version="6.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview2-final" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
  </ItemGroup>

Below is the raw exception details.

System.MissingMethodException: Method not found: 'Microsoft.Extensions.Configuration.IConfiguration Microsoft.Extensions.Logging.LoggerFactory.get_Configuration()'.
   at Microsoft.AspNetCore.ApplicationInsights.HostingStartup.ApplicationInsightsLoggerStartupFilter.<>c__DisplayClass0_1.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Program.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;

namespace Phoenix
{
    public class AppProgram
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .ConfigureLogging(factory =>
                {
                    factory.AddConsole();
                    factory.AddDebug();
                })
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
    }
}

Startup.cs (I had to comment out loggerFactory.AddSeriLog() call because it was generating error just after I updated all the packages.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    services.AddSwaggerGen(c =>
    {
        // removed for brevity
    });

    // DI statements have been removed for brevity.

    Log.Logger = new LoggerConfiguration()
        .ReadFrom.Configuration(Configuration)
        .CreateLogger();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    //loggerFactory.AddSerilog();

    app.UseMvc();

    app.UseSwagger();

    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
    });

}

As suggested in the error message from loggerFactory.AddSerilog();, I tried adding services.AddSeriLog() in my ConfigureServices method.

I also tried installing package Microsoft.Extensions.Logging, also didn't fix.

I also tried replacing content of Program.cs file from the new template as below. This also didn't work.

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
}

Can someone please help me fixing this issue?

Update

Adding package Microsoft.AspNetCore.All solves the issue. But I really do not want to add this package as this adds many unwanted references packaged into this single package.

解决方案

Required package is

Microsoft.Extensions.Logging.Configuration

I added the package which resolved the issue.

<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0-preview2-final" />

这篇关于从2.0.0-preview1-final升级到2.0.0-preview2-final之后的System.MissingMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 23:20