hi team
Message Error: Volo.Abp.AbpException: 'Options must be derived from the Volo.Abp.Options.AbpDynamicOptionsManager`1!' in this function "await IdentityOptions.SetAsync(); "when i test register any idea ?
7 Answer(s)
-
0
Hello,
Can you please provide detailed steps to reproduce the issue?
-
0
here is registration function
public virtual async Task<IdentityUserDto> RegisterAsync(RegisterDto input) {
await CheckSelfRegistrationAsync(); await IdentityOptions.SetAsync(); var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.EmailAddress, CurrentTenant.Id); input.MapExtraPropertiesTo(user); (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); await UserManager.SetEmailAsync(user, input.EmailAddress); await UserManager.AddDefaultRolesAsync(user); return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); } and i use using Microsoft.Extensions.Options; , this function throw exception in await IdentityOptions.SetAsync();
Message Error: Volo.Abp.AbpException: 'Options must be derived from the Volo.Abp.Options.AbpDynamicOptionsManager`1!' in this function "await
-
0
hi
Please share the full code of
registration function
. Thanks -
0
using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Volo.Abp.Account.Emailing; using Volo.Abp.Account.Localization; using Volo.Abp.Account.Settings; using Volo.Abp.Application.Services; using Volo.Abp.Auditing; using Volo.Abp.DependencyInjection; using Volo.Abp.Identity; using Volo.Abp.ObjectExtending; using Volo.Abp.Settings; using IdentityUser = Volo.Abp.Identity.IdentityUser; namespace Volo.Abp.Account; [Audited] public class AccountAppService : ApplicationService, IAccountAppService, ITransientDependency { protected IIdentityRoleRepository RoleRepository { get; } protected IdentityUserManager UserManager { get; } protected IAccountEmailer AccountEmailer { get; } protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } protected IOptions<IdentityOptions> IdentityOptions { get; } public AccountAppService( IdentityUserManager userManager, IIdentityRoleRepository roleRepository, IAccountEmailer accountEmailer, IdentitySecurityLogManager identitySecurityLogManager, IOptions<IdentityOptions> identityOptions) { RoleRepository = roleRepository; AccountEmailer = accountEmailer; IdentitySecurityLogManager = identitySecurityLogManager; UserManager = userManager; IdentityOptions = identityOptions; LocalizationResource = typeof(AccountResource); } public virtual async Task<IdentityUserDto> RegisterAsync(RegisterDto input) { await CheckSelfRegistrationAsync(); await IdentityOptions.SetAsync(); var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.EmailAddress, CurrentTenant.Id); input.MapExtraPropertiesTo(user); (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); await UserManager.SetEmailAsync(user, input.EmailAddress); await UserManager.AddDefaultRolesAsync(user); return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); } public virtual async Task SendPasswordResetCodeAsync(SendPasswordResetCodeDto input) { var user = await GetUserByEmailAsync(input.Email); var resetToken = await UserManager.GeneratePasswordResetTokenAsync(user); await AccountEmailer.SendPasswordResetLinkAsync(user, resetToken, input.AppName, input.ReturnUrl, input.ReturnUrlHash); } public virtual async Task ResetPasswordAsync(ResetPasswordDto input) { await IdentityOptions.SetAsync(); var user = await UserManager.GetByIdAsync(input.UserId); (await UserManager.ResetPasswordAsync(user, input.ResetToken, input.Password)).CheckErrors(); await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext { Identity = IdentitySecurityLogIdentityConsts.Identity, Action = IdentitySecurityLogActionConsts.ChangePassword }); } protected virtual async Task<IdentityUser> GetUserByEmailAsync(string email) { var user = await UserManager.FindByEmailAsync(email); if (user == null) { throw new UserFriendlyException(L["Volo.Account:InvalidEmailAddress", email]); } return user; } protected virtual async Task CheckSelfRegistrationAsync() { if (!await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled)) { throw new UserFriendlyException(L["SelfRegistrationDisabledMessage"]); } } }
-
0
hi
Is your app depend on the
AbpIdentityDomainModule
?Because we need this line of code.
context.Services.AddAbpDynamicOptions<IdentityOptions, AbpIdentityOptionsManager>();
-
0
ok, i user Volo.Abp.Identity.Domain as a project reference to Volo.Abp.Account.HttpApi and in AbpIdentityDomainModule here the code
public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAutoMapperObjectMapper<AbpIdentityDomainModule>();
Configure<AbpAutoMapperOptions>(options => { options.AddProfile<IdentityDomainMappingProfile>(validate: true); }); Configure<AbpDistributedEntityEventOptions>(options => { options.EtoMappings.Add<IdentityUser, UserEto>(typeof(AbpIdentityDomainModule)); options.EtoMappings.Add<IdentityClaimType, IdentityClaimTypeEto>(typeof(AbpIdentityDomainModule)); options.EtoMappings.Add<IdentityRole, IdentityRoleEto>(typeof(AbpIdentityDomainModule)); options.EtoMappings.Add<OrganizationUnit, OrganizationUnitEto>(typeof(AbpIdentityDomainModule)); options.AutoEventSelectors.Add<IdentityUser>(); options.AutoEventSelectors.Add<IdentityRole>(); }); var identityBuilder = context.Services.AddAbpIdentity(options => { options.User.RequireUniqueEmail = true; }); context.Services.AddObjectAccessor(identityBuilder); context.Services.ExecutePreConfiguredActions(identityBuilder); Configure<IdentityOptions>(options => { options.ClaimsIdentity.UserIdClaimType = AbpClaimTypes.UserId; options.ClaimsIdentity.UserNameClaimType = AbpClaimTypes.UserName; options.ClaimsIdentity.RoleClaimType = AbpClaimTypes.Role; options.ClaimsIdentity.EmailClaimType = AbpClaimTypes.Email; }); context.Services.AddAbpDynamicOptions<IdentityOptions, AbpIdentityOptionsManager>(); }
that's what you mean ???
-
0
hi
Can you share a simple project to reproduce?
liming.ma@volosoft.com