Michael
Michael

Reputation: 61

Error on System.MethodAccessException in 'Microsoft.Extensions.Logging.Configuration.LoggerProvider

I use visual studio to create the new web project which is MVC in .net Framework 4.8 under .net core 2.2.

When I use nuget to get the Microsoft.EntityFrameworkCore.SqlServer and start to run (debug), I got the below exception

System.MethodAccessException: 'Attempt by method 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(System.Type)' 
to access method 'Microsoft.Extensions.Logging.ProviderAliasUtilities.GetAlias(System.Type)' failed.'

My Project properties is only this

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

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <DebugType>full</DebugType>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.8" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
  </ItemGroup>
</Project>

Can you help to solve this problem ? Thank you

Upvotes: 0

Views: 2159

Answers (1)

Aziz Alzayed
Aziz Alzayed

Reputation: 236

the solution was downloading the Microsoft.Extensions packages and updating the versions so it can be equivalents. here were the main answer and the discussions:

I suspect the issue is due to mismatched package versions. You will certainly need to update all EntityFrameworkCore packages to the same version. I expect you will also need to pull in the latest 3.1 versions of Microsoft.Extensions packages, since the EF packages depend on the 3.1 versions of these packages.

discussion

Upvotes: 1

Related Questions