Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
The type initializer for 'Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions' threw an exception.'

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();
            });
//...

it says this error:

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?

Inner exception is:

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 is the latest version

Identity is included into application.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You need to update Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation

Faced the same problem, created MVC Proj with razor template project in VS2022 was using 6.0.0-preview.5.21301.17 so I updated package to 6.0.0-preview.7.21378.6

enter image description here

over 4 years ago · Santiago Trujillo Report

0

Well, when I tried to add package Microsoft.Extensions.Logging, it says that .NET Core 6.0 is version that is not supported.

I transferred from VS 2022 Preview and .NET CORE 6 Preview to VS 2019 and .NET Core 5 and now everything works.

So it was a clash between the new preview versions (or maybe a new Microsoft bug?) :D.

over 4 years ago · Santiago Trujillo Report

0

I am having this same issue, but dont have the option of switching from .NET CORE 6 Preview.

Here is my csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <Description>Application description goes here</Description>
    <!-- NuGet Version Number (no pre-release identifiers)-->
    <VersionPrefix>1.0.0</VersionPrefix>
    <Authors>Your name here</Authors>
    <TargetFramework>net6.0</TargetFramework>
    <PackageProjectUrl>--redacted--</PackageProjectUrl>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <!-- Should be major.minor.0.0-->
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <!-- Should be major.minor.version.0-->
    <FileVersion>1.0.0.0</FileVersion>
    <TypeScriptToolsVersion>3.3</TypeScriptToolsVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="10.1.1" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
    <PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0-preview.7.21378.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.7.21378.4" />
    <PackageReference Include="Microsoft.jQuery.Unobtrusive.Ajax" Version="3.2.6" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0-preview.7.21413.1" />
    <PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\lib\" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyProject.Data\\MyProject.Data.csproj" />
    <ProjectReference Include="..\\MyProject.Services\\MyProject.Services.csproj" />
  </ItemGroup>
</Project>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!