question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MissingMethodException when using version 6.28.1

See original GitHub issue

Version

<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.28.1" />

Where is the issue?

  • S.IM.Tokens.Jwt

Is this a new or an existing app? The app is in production and I haven’t upgraded Microsoft.IdentityModel.*, but started seeing this issue.

Repro Update NuGet package from version 6.27.0 to 6.28.1. Run code below:

public bool TryValidateJwtToken(string token, IEnumerable<string> validAudiences, out IEnumerable<Claim> claims)
{
    claims = null;
    try
    {
        var handler = new JwtSecurityTokenHandler();
        var parameters = new TokenValidationParameters
        {
            RequireSignedTokens = true,
            IssuerSigningKeys = discoveryResponse.KeySet.Keys.Select(key => new RsaSecurityKey(new RSAParameters
            {
                Exponent = Base64UrlEncoder.DecodeBytes(key.E),
                Modulus = Base64UrlEncoder.DecodeBytes(key.N)
            })
            { KeyId = key.Kid }),
            ValidateIssuer = true,
            ValidIssuer = discoveryResponse.Issuer,
            ValidateAudience = true,
            ValidAudiences = validAudiences,
        };
        var claimsPrincipal = handler.ValidateToken(token, parameters, out _);
        claims = claimsPrincipal.Claims;
    }
    catch (Exception ex)
    {
        // Goes BOOM!
    }

    return claims != null;
}

Expected behavior In version 6.27.0 we got parsed claims. That is what we expect to happen.

Actual behavior In version 6.28.1 we’re getting the following error both when targeting netstandard2.0 (which we use) and net6.0:

"Method not found: 'Boolean Microsoft.IdentityModel.Tokens.TokenUtilities.IsRecoverableConfiguration(Microsoft.IdentityModel.Tokens.TokenValidationParameters, Microsoft.IdentityModel.Tokens.BaseConfiguration, Microsoft.IdentityModel.Tokens.BaseConfiguration ByRef)'."

Stack trace:

{System.MissingMethodException: Method not found: 'Boolean Microsoft.IdentityModel.Tokens.TokenUtilities.IsRecoverableConfiguration(Microsoft.IdentityModel.Tokens.TokenValidationParameters, Microsoft.IdentityModel.Tokens.BaseConfiguration, Microsoft.IdentityModel.Tokens.BaseConfiguration ByRef)'.
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, JwtSecurityToken outerToken, TokenValidationParameters validationParameters, SecurityToken& signatureValidatedToken)
   at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
   at [REDACTED].TryValidateJwtToken(String token, IEnumerable`1 validAudiences, IEnumerable`1& claims) in [REDACTED]\TokenValidator.cs:line [REDACTED]}

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
brentschmaltzcommented, Apr 11, 2023

@jouni-kantola we had started an effort to check that all assemblies are the same version to avoid such issues. That effort was bumped from the list. I pointed out this issue to the team, adding that logic may get a higher priority now.

1reaction
sipsorcerycommented, Apr 22, 2023

I’m getting the same exception after updating to the latest stabke nuget packages. My relevant packages seem to be:

<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.5" />

The resulting System.IdentityModel.Tokens.Jwt assembly version in my executable directory is 6.24.0.31013.

Update:

Explicitly adding a package reference resolves the problem. This wasn’t needed previously.

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.29.0" />

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.MissingMethodException: Method not found?
This is a problem which can occur when there is an old version of a DLL still lingering somewhere around. Make sure that...
Read more >
MissingMethodException / "Method not found" after update ...
MissingMethodException s usually indicate that you have old DLLs lurking around somewhere that are not binary-compatible with the version ...
Read more >
MissingMethodException Class (System)
MissingMethodException is thrown when code in a dependent assembly attempts to access a missing method in an assembly that was modified. MissingMethodException ...
Read more >
MissingMethodException at app start when using ...
MissingMethodException at app start when using AutoGeneratedBindingRedirects(true) with app ... Visual Studiowindows 10.0visual studio 2019 version 16.3.
Read more >
System.IdentityModel.Tokens.Jwt 6.32.1
Includes types that provide support for creating, serializing and validating JSON Web Tokens. Product, Versions Compatible and additional computed target ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found