AzureAD / azure-activedirectory-identitymodel-extensions-for-dotnet

IdentityModel extensions for .Net
MIT License
1.06k stars 401 forks source link

[Bug] Could not load type 'ExceptionType' from assembly 'Microsoft.IdentityModel.Tokens #2945

Open pantonis opened 1 month ago

pantonis commented 1 month ago

Which version of Microsoft.IdentityModel are you using? Note that to get help, you need to run the latest version.

8.1.2

Where is the issue?

After updating from 8.0.2 to 8.1.2 and when calling services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); in ConfigureServices in Startup.cs we receive the following exception

Unable to load one or more of the requested types.
Could not load type 'ExceptionType' from assembly 'Microsoft.IdentityModel.Tokens, Version=8.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.IdentityModel.Tokens.InternalTokenValidationResult' from assembly 'Microsoft.IdentityModel.Tokens, Version=8.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Could not load type 'Microsoft.IdentityModel.Tokens.InternalTokenValidationResult' from assembly 'Microsoft.IdentityModel.Tokens, Version=8.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.<>c__DisplayClass12_1.<AddAutoMapperClasses>b__6(Assembly a)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.AddAutoMapperClasses(IServiceCollection services, Action`2 configAction, IEnumerable`1 assembliesToScan, ServiceLifetime serviceLifetime)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.AddAutoMapper(IServiceCollection services, Assembly[] assemblies)
   at MyService.Web.Web.Startup.ConfigureServices(IServiceCollection services) in C:\\Github\MyService\src\MyService.Web\Startup.cs:line 96
pmaytak commented 3 weeks ago

This may be related to https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/pull/2888 in 8.1.2 which reverts a change in the previous version.

Can you verify that all IdentityModel.* packages are of the same version - 8.1.2 (or better 8.2.0)?

pantonis commented 3 weeks ago

I updated to latest 8.2.0 and still the same bug Below you can find the version of IdentityModel.* packages

Microsoft.IdentityModel.Abstractions.dll => 8.2.0.51101 Microsoft.IdentityModel.JsonWebTokens.dll => 8.0.2.50822 Microsoft.IdentityModel.Logging.dll => 8.2.0.51101 Microsoft.IdentityModel.Protocols.dll => 7.1.2.41121 Microsoft.IdentityModel.Protocols.OpenIdConnect.dll => 7.1.2.41121 Microsoft.IdentityModel.Tokens.dll => 8.2.0.51101

pantonis commented 2 weeks ago

anyone?