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

查看:24
本文介绍了“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.

推荐答案

当我尝试将 Blazor WASM Asp.net 托管项目从 5.0 升级到 6.0.0 时出现完全相同的错误.我正在使用 Serilog,但不确定这是否是一个因素.

Getting the exact same error when I try to upgrade my Blazor WASM Asp.net Hosted project from 5.0 to 6.0.0. I am using Serilog, but am not sure if that is a factor.

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

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