'System.MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.Identity.DataProtectorTokenProvider

Stil on same project where I had issue DI Registration service type .net core 3.0. Now when that is fixed I'm getting new error. Now my code looks:

    services.AddDbContext<ApplicationIdentityDbContext>(options =>
        options.UseSqlServer(configuration.GetConnectionString("Default")));

    services.AddIdentityCore<ApplicationUser>(options =>
        {
            options.Password.RequireDigit = false;
            options.Password.RequireLowercase = false;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = false;
            options.Password.RequiredLength = 4;

            options.SignIn.RequireConfirmedEmail = true;
            options.Tokens.ProviderMap.Add("CustomEmailConfirmation",
                new TokenProviderDescriptor(
                    typeof(CustomEmailConfirmationTokenProvider<IdentityUser>)));

            options.Tokens.EmailConfirmationTokenProvider = "CustomEmailConfirmation";

        })
        .AddEntityFrameworkStores<ApplicationIdentityDbContext>();

    services.AddTransient(o =>
    {
        var service = new CustomEmailConfirmationTokenProvider<IdentityUser>(o.GetService<IDataProtectionProvider>(), o.GetService<IOptions<DataProtectionTokenProviderOptions>>(), o.GetService<ILogger<DataProtectorTokenProvider<IdentityUser>>>());

        return service;
    });

And error is:

System.MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.Identity.DataProtectorTokenProvider1..ctor(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider, Microsoft.Extensions.Options.IOptions1)'.



Solution 1:[1]

I've had the same issue and the problem is related to the packages itself.

Basically the problem was that many of those Microsoft.AspNetCore.* packages are now moved to Microsoft.AspNetCore.App framework, so you remove your Microsoft.AspNetCore.Identity reference and add this to your project:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

I've noticed that my constructor (same as yours) is missing additional parameter ILogger<DataProtectorTokenProvider<TUser>>, which you can see in .NET Core 3.* versions on this link.

Solution 2:[2]

I ran into the same issue while creating a custom JWT provider for password reset emails. Instead of inheriting from DataProtectorTokenProvider<TUser>, I just implemented the IUserTwoFactorTokenProvider<TUser> interface directly. You will need to implement the CanGenerateTwoFactorTokenAsync method yourself but you can avoid the hacky framework reference.

From:

public class MyTokenProvider<TUser> 
    : DataProtectorTokenProvider<TUser> where TUser : IdentityUser

To:

public class MyTokenProvider<TUser> 
    : IUserTwoFactorTokenProvider<TUser> where TUser : IdentityUser

Solution 3:[3]

I had the same problem referencing the Microsoft.AspNetCore.Authentication.JwtBearer package and using the AddJwtBearer extension method. Seems like verison 5.0.16 is ok,but 6.0.0, 6.0.3, and 6.0.4 are broken (didn't bother trying 6.0.1 nor 6.0.2) - they pull in an incompatible version of Microsoft.IdentityModel.Tokens.dll. So the solution for me was to downgrade to 5.0.16

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zhuber
Solution 2 kwinsor5
Solution 3 S Waye