Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
14 tasks
pantonis opened this issue Oct 28, 2024 · 4 comments
Open
14 tasks
Labels
Dependency Mismatch Transitive dependency might be at play and create issues resulting in incorrect versions of a class

Comments

@pantonis
Copy link

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?

  • M.IM.JsonWebTokens
  • M.IM.KeyVaultExtensions
  • M.IM.Logging
  • M.IM.ManagedKeyVaultSecurityKey
  • M.IM.Protocols
  • M.IM.Protocols.OpenIdConnect
  • M.IM.Protocols.SignedHttpRequest
  • M.IM.Protocols.WsFederation
  • M.IM.TestExtensions
  • M.IM.Tokens
  • M.IM.Tokens.Saml
  • M.IM.Validators
  • M.IM.Xml
  • S.IM.Tokens.Jwt
  • Other (please describe)

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
@pantonis pantonis changed the title [Bug] [Bug] Could not load type 'ExceptionType' from assembly 'Microsoft.IdentityModel.Tokens Oct 29, 2024
@pmaytak
Copy link
Contributor

pmaytak commented Nov 5, 2024

This may be related to #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)?

@pmaytak pmaytak added More info needed Customer has been asked for more information and removed needs attention untriaged labels Nov 5, 2024
@pantonis
Copy link
Author

pantonis commented Nov 5, 2024

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
Copy link
Author

anyone?

@pmaytak
Copy link
Contributor

pmaytak commented Jan 2, 2025

In the case above JsonWebTokens version should match Tokens package version (8.2.0). Ideally all IdentityModel.* packages should be of the same version.

Seems like AddAutoMapper expects assemblies with AutoMapper profiles; so passing specific ones instead of loading all may prevent this issue.

@pmaytak pmaytak added Dependency Mismatch Transitive dependency might be at play and create issues resulting in incorrect versions of a class and removed More info needed Customer has been asked for more information labels Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dependency Mismatch Transitive dependency might be at play and create issues resulting in incorrect versions of a class
Projects
None yet
Development

No branches or pull requests

2 participants