Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda