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

3

9

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)'.

Suffragan answered 21/11, 2019 at 11:17 Comment(0)
L
7

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.

Lankester answered 5/6, 2020 at 6:21 Comment(2)
I just want to thank you for answering this question - this solution worked for me but with a caveat. My Function App was targeted for .Net Core 2.1 but my shared libraries were targeted for .Net Standard 2.0 (which should be the corresponding Core to Standard version) however this was the likely cause of the package version mismatch. Changing the class libraries to Core 2.1 and doing the steps you've outlined worked for me.. I've lived with this problem for so long, I don't know what to do now...Adapt
Minor thing that is hard to notice which makes it even more frustrating, but that's how programming works I guessLankester
C
1

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
Carbone answered 21/5, 2021 at 19:52 Comment(0)
S
0

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

Sciuroid answered 9/5, 2022 at 23:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.