Could not load type 'Microsoft.IdentityModel.Abstractions.NullIdentityModelLogger' from assembly 'Microsoft.IdentityModel.Abstractions

Jay Prakash 0 Reputation points Microsoft Employee
2024-12-30T09:36:20.9466667+00:00

When calling

Microsoft.AspNetCore.Authentication.Core.AuthenticationHandlerProvider.GetHandlerAsync()

Got below exception

System.TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Logging.LogHelper' threw an exception.
 ---> System.TypeLoadException: Could not load type 'Microsoft.IdentityModel.Abstractions.NullIdentityModelLogger' from assembly 'Microsoft.IdentityModel.Abstractions, Version=8.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at Microsoft.IdentityModel.Logging.LogHelper..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.IdentityModel.Logging.LogHelper.get_Logger()
   at Microsoft.Identity.Web.MicrosoftIdentityBaseAuthenticationBuilder.SetIdentityModelLogger(IServiceProvider serviceProvider)
   at Microsoft.Identity.Web.MicrosoftIdentityWebAppAuthenticationBuilderExtensions.<>c__DisplayClass5_0.<AddMicrosoftIdentityWebAppInternal>b__4(OpenIdConnectOptions options, IServiceProvider serviceProvider, IMergedOptionsStore mergedOptionsMonitor, IOptionsMonitor`1 msIdOptionsMonitor, IOptions`1 msIdOptions)
   at Microsoft.Extensions.Options.ConfigureNamedOptions`5.Configure(String name, TOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.Lazy`1.CreateValue()
   at Microsoft.Extensions.Options.OptionsCache`1.GetOrAdd[TArg](String name, Func`3 createOptions, TArg factoryArgument)
   at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name)
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme)

It persisted until restarting the application. Restarting the application resolved the error. Is it an issue coming from Microsoft.IdentityModel.Abstractations?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,717 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.