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

IDX12729: Exception **System.MissingMethodException: Method not found:** thrown when reading the access token. #2574

Open
1 task
Manishd79 opened this issue Apr 29, 2024 · 2 comments

Comments

@Manishd79
Copy link

Which version of Microsoft.IdentityModel are you using?
7.3.1

Where is the issue?

  • S.IM.Tokens.Jwt

Is this a new or an existing app?
a. The app is in production and I have upgraded to a new version of Microsoft.IdentityModel.*

Repro
Trying to decode the JWT token is resulting into exception. The token is retrieved using certificate and trying to fetch Payload claim values. The exception encountered is:

{"IDX12729: Unable to decode the header 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCIsImtpZCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCJ9' as Base64Url encoded string."}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
InnerException: {"Method not found: 'Void System.Text.Json.Utf8JsonReader..ctor(System.ReadOnlySpan1<Byte>, System.Text.Json.JsonReaderOptions)'."} Message: "IDX12729: Unable to decode the header 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCIsImtpZCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCJ9' as Base64Url encoded string." ParamName: null Source: "System.IdentityModel.Tokens.Jwt" StackTrace: " at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.Decode(String[] tokenParts, String rawData)\r\n at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ReadJwtToken(String token)\r\n at Kailani.Hfs.V1.Client.AD.AzureADClient.GetPayloadClaimValueFromAccessToken(String claim, String accessToken) in G:\\OneEsWorkingDirectory\\Storage\\XSync\\Dev\\src\\Kailani\\Kailani.Hfs.Client.AD\\AzureADClient.cs:line 690" TargetSite: {Void Decode(System.String[], System.String)} Trace> EventLevel: Error Message: -------Exception information------ System.ArgumentException: IDX12729: Unable to decode the header 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCIsImtpZCI6IkwxS2ZLRklfam5YYndXYzIyeFp4dzFzVUhIMCJ9' as Base64Url encoded string. ---> System.MissingMethodException: Method not found: 'Void System.Text.Json.Utf8JsonReader..ctor(System.ReadOnlySpan1, System.Text.Json.JsonReaderOptions)'.
at System.IdentityModel.Tokens.Jwt.JwtHeader..ctor(String json)
at System.IdentityModel.Tokens.Jwt.JwtHeader.Base64UrlDeserialize(String base64UrlEncodedJsonString)
at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.Decode(String[] tokenParts, String rawData)
--- End of inner exception stack trace ---
at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.Decode(String[] tokenParts, String rawData)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ReadJwtToken(String token)
at GetPayloadClaimValueFromAccessToken(String claim, String accessToken) in AzureADClient.cs:line 690
------Begin Inner exception extra info------
------End inner exception extra info-----

It is very interesting that performing a same action in a sample app on my dev box, works fine!! For this App, I have following NuGet
Microsoft.IdentityModel.*.7.5.1
System.IdentityModel.Tokens.Jwt.7.5.1
System.Text.Json.4.7.2

var handler = new JwtSecurityTokenHandler();
var jwtToken = handler.ReadJwtToken(accessToken);
return jwtToken.Claims.FirstOrDefault(c => c.Type == claim)?.Value;

Expected behavior
A clear and concise description of what you expected to happen (or code).

Actual behavior
A clear and concise description of what happens, e.g. an exception is thrown, UI freezes.

Possible solution

Additional context / logs / screenshots / links to code

Add any other context about the problem here, such as logs and screenshots or links to code.

@Manishd79 Manishd79 changed the title IDx129729: Exception **System.MissingMethodException: Method not found:** thrown when reading the access token IDX12729: Exception **System.MissingMethodException: Method not found:** thrown when reading the access token. Apr 29, 2024
@jmprieur
Copy link
Contributor

jmprieur commented Apr 29, 2024

@Manishd79: Did you make sure that all the Microsoft.IdentityModel* assemblies have the same version?
To check, you can run:

dotnet list yourcsrpoj.csproj package --include-transitive

@Manishd79
Copy link
Author

@jmprieur thx for your response, since my project is in a repo I cannot use that command. However here are details from the.csproj file and all are 7.3.1

$(PkgMicrosoft_Identity_Client)\lib\net45\Microsoft.Identity.Client.dll True $(PkgMicrosoft_IdentityModel_Abstractions)\lib\net462\Microsoft.IdentityModel.Abstractions.dll True $(PkgMicrosoft_IdentityModel_Tokens)\lib\net462\Microsoft.IdentityModel.JsonWebTokens.dll True $(PkgMicrosoft_IdentityModel_Tokens)\lib\net462\Microsoft.IdentityModel.Tokens.dll True $(PkgMicrosoft_IdentityModel_Logging_7_3_1)\lib\net462\Microsoft.IdentityModel.Logging.dll True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants