“Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions"的类型初始值设定项引发异常. [英] The type initializer for 'Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions' threw an exception.'

查看:34
本文介绍了“Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions"的类型初始值设定项引发异常.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 .NET Core 应用程序,我想启动一个应用程序,但它在这行代码中说:

I am making an .NET Core application and I wanted to start an app but it says at this line of code:

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
//...

它说这个错误:

System.TypeInitializationException: 'Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions' 的类型初始值设定项引发异常.'

System.TypeInitializationException: 'The type initializer for 'Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions' threw an exception.'

这是新事物,我以前在启动应用程序时从未见过.我该如何解决?

that is something new and I never seen that before while starting an application. How can I fix it?

内部异常是:

找不到方法:'System.Action`4Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.EventId, System.String, Boolean)'.

Method not found: 'System.Action`4<Microsoft.Extensions.Logging.ILogger,!!0,!!1,System.Exception> Microsoft.Extensions.Logging.LoggerMessage.Define(Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.EventId, System.String, Boolean)'.

Main.cs

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

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

.NET Core 6.0 是最新版本

.NET Core 6.0 is the latest version

身份包含在应用程序中.

Identity is included into application.

推荐答案

我遇到了同样的问题.为了实验,我创建了一个新项目,并在其中添加了最新版本的 Microsoft.Extensions.Logging(目前为 6.0.0-preview.7.21377.19).该项目因与您相同的错误而崩溃.问题在于 LoggerMessage.Define 中没有四参数重载.将软件包降级到 6.0.0-preview.6.21352.12 版对我有帮助.

I faced the same problem. For the experiment, I created a new project and added the latest version of Microsoft.Extensions.Logging to it (currently 6.0.0-preview.7.21377.19). The project crashes with the same error as yours. The problem is that there is no four-argument overload in LoggerMessage.Define. Downgrading the package to version 6.0.0-preview.6.21352.12 helped me.

这篇关于“Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions"的类型初始值设定项引发异常.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆