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.DataProtectorTokenProvider
1..ctor(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider, Microsoft.Extensions.Options.IOptions
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With