dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.72k stars 558 forks source link

TypeInitializationException when upgrading from 8.0.0 to 8.1.0 #5700

Open rdeherder opened 5 days ago

rdeherder commented 5 days ago

Describe the bug Using dotnet 8, after upgrading from 8.0.0 to 8.1.0 I get a TypeInitializationException:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'System.IdentityModel.Tokens.Jwt.JsonExtensions' threw an exception.
  Source=System.IdentityModel.Tokens.Jwt
  StackTrace:
   at System.IdentityModel.Tokens.Jwt.JsonExtensions.get_Serializer()
   at System.IdentityModel.Tokens.Jwt.JsonExtensions.SerializeToJson(Object value)
   at System.IdentityModel.Tokens.Jwt.JwtHeader.SerializeToJson()
   at System.IdentityModel.Tokens.Jwt.JwtHeader.Base64UrlEncode()
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateJwtSecurityTokenPrivate(String issuer, String audience, ClaimsIdentity subject, Nullable`1 notBefore, Nullable`1 expires, Nullable`1 issuedAt, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, IDictionary`2 claimCollection, String tokenType, IDictionary`2 additionalHeaderClaims, IDictionary`2 additionalInnerHeaderClaims)
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateToken(SecurityTokenDescriptor tokenDescriptor)
   at Gigantisch.Services.LegacyAuthenticationService.<LogIn>d__4.MoveNext() in C:\Projects\GigantischV3\Gigantisch.Services\LegacyAuthenticationService.cs:line 72

  This exception was originally thrown at this call stack:

Inner Exception 1:
TypeLoadException: Could not load type 'Microsoft.IdentityModel.Json.JsonConvert' from assembly 'Microsoft.IdentityModel.Tokens, Version=8.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

when calling the JwtSecurityTokenHandler.CreateToken();

To Reproduce Create an Asp.NET 8 project targeting .net 8. Add System.ServiceModel.Federation package reference. Add code that tries to create a token from a SecurityTokenDescriptor instance that only has Subject, Expires and SigningCredentials properties filled in.

Expected behavior The JwtSecurityTokenHandler returns a token when calling CreateToken().