In .NETCore, While running the application in Program.cs
file at CreateWebHostBuilder(args).Build().Run();
I'm getting the 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.'"
in the Method
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
How to resolve this. I tried by uninstalling and Installing Microsoft.AspNetCore but no use, Please see the screenshot of my Dependencies
Except theMicrosoft.Extension.Logging all the versions of dependcies are same. is there any problem that version difference. can someone help me to sort out this.
Microsoft. Extensions. Logging can also be used for applications that don't use dependency injection, although simple logging can be easier to set up. Microsoft.
For example, the Console ILoggerProvider writes the logs to the console. This interface is used to create a custom instance of an ILogger . ILoggerFactory : This interface registers one or more ILoggerProvider instances and provides the CreateLogger() method used to create an instance of ILogger .
The ILoggerFactory is the factory interface for creating an appropriate ILogger type instance and also for adding the ILoggerProvider instance. The Logging API includes the built-in LoggerFactory class that implements the ILoggerFactory interface.
When I create a ASP.NET 2.2 project and add the package Microsoft.EntityFrameworkCore 3.1, I get the same error.
The solution is to update all Microsoft.Extensions.Logging.* package to the version 3.1.
The exception says the problem resides in 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory' (contained in Microsoft.Extensions.Logging.Configuration assembly).
As Microsoft says here: https://docs.microsoft.com/en-us/dotnet/api/system.methodaccessexception?redirectedfrom=MSDN&view=net-5.0
The MethodAccessException exception is thrown in situations such as the following:
Basically, you have a reference to Microsoft.Extensions.Logging '3.1.6', but another reference to Microsoft.Extensions.Configuration.Logging version '2.2.0', and that assembly was surely compiled before Microsoft.Extensions.Logging '3.1.6'
All can be resolved modifying/adding an explicit Package Reference in your project:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With