Open Closed

'IdentityUserUpdateDto' does not contain a definition for 'Password' and no accessible extension method 'Password' accepting a first argument of type 'IdentityUserUpdateDto' could be found #4965


User avatar
0
datkinson created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v7.1.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:Error CS1061 'IdentityUserUpdateDto' does not contain a definition for 'Password' and no accessible extension method 'Password' accepting a first argument of type 'IdentityUserUpdateDto' could be found (are you missing a using directive or an assembly reference?) ios.systems.Application D:\Repos\IOS.Systems\src\ios.systems.Application\Volo\Abp\Identity\IdentityUserAppService.cs 125 Active

Error CS1061 'IdentityUserUpdateDto' does not contain a definition for 'Password' and no accessible extension method 'Password' accepting a first argument of type 'IdentityUserUpdateDto' could be found (are you missing a using directive or an assembly reference?) ios.systems.Application D:\Repos\IOS.Systems\src\ios.systems.Application\Volo\Abp\Identity\IdentityUserAppService.cs 128 Active

  • Steps to reproduce the issue:"

I am trying to create a custom IdentityUserAppService. I copied the source for the standard IdentityUserAppService and changed it to a custom class that inherits from the standard class. I have not customized any of the methods yet. Everything looks good so far, except for the error I'm getting when referencing the Password property of the IdentityUserUpdateDto. How do I resolve the error? Here is my code. The problematic items are in bold.

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.Identity;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IIdentityUserAppService), typeof(IdentityUserAppService), typeof(IosIdentityUserAppService))]
public class IosIdentityUserAppService : IdentityUserAppService
{
 public IosIdentityUserAppService(
 IdentityUserManager userManager, 
 IIdentityUserRepository userRepository, 
 IIdentityRoleRepository roleRepository, 
 IOrganizationUnitRepository organizationUnitRepository, 
 IIdentityClaimTypeRepository identityClaimTypeRepository, 
 IdentityProTwoFactorManager identityProTwoFactorManager, 
 IOptions\<IdentityOptions> identityOptions, 
 IDistributedEventBus distributedEventBus, 
 IOptions\<AbpIdentityOptions> abpIdentityOptions, 
 IPermissionChecker permissionChecker)
 : base(
 userManager, 
 userRepository, 
 roleRepository, 
 organizationUnitRepository, 
 identityClaimTypeRepository, 
 identityProTwoFactorManager,
 identityOptions,
 distributedEventBus,
 abpIdentityOptions,
 permissionChecker)
 {
 }
 //TODO: [Authorize(IdentityPermissions.Users.Default)] should go the IdentityUserAppService class.
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<IdentityUserDto> GetAsync(Guid id)
 {
 return ObjectMapper.Map\<IdentityUser, IdentityUserDto>(
 await UserManager.GetByIdAsync(id)
 );
 }
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input)
 {
 var count = await UserRepository.GetCountAsync(input.Filter);
 var list = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
 return new PagedResultDto\<IdentityUserDto>(
 count,
 ObjectMapper.Map\<List<IdentityUser>, List\<IdentityUserDto>>(list)
 );
 }
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
 {
 //TODO: Should also include roles of the related OUs.
 var roles = await UserRepository.GetRolesAsync(id);
 return new ListResultDto\<IdentityRoleDto>(
 ObjectMapper.Map\<List<IdentityRole>, List\<IdentityRoleDto>>(roles)
 );
 }
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<ListResultDto<IdentityRoleDto>> GetAssignableRolesAsync()
 {
 var list = await RoleRepository.GetListAsync();
 return new ListResultDto\<IdentityRoleDto>(
 ObjectMapper.Map\<List<IdentityRole>, List\<IdentityRoleDto>>(list));
 }
 [Authorize(IdentityPermissions.Users.Create)]
 public override async Task\<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
 {
 await IdentityOptions.SetAsync();
 var user = new IdentityUser(
 GuidGenerator.Create(),
 input.UserName,
 input.Email,
 CurrentTenant.Id
 );
 input.MapExtraPropertiesTo(user);
 (await UserManager.CreateAsync(user, input.Password)).CheckErrors();
 await UpdateUserByInput(user, input);
 (await UserManager.UpdateAsync(user)).CheckErrors();
 await CurrentUnitOfWork.SaveChangesAsync();
 return ObjectMapper.Map\<IdentityUser, IdentityUserDto>(user);
 }
 [Authorize(IdentityPermissions.Users.Update)]
 public override async Task\<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input)
 {
 await IdentityOptions.SetAsync();
 var user = await UserManager.GetByIdAsync(id);
 user.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
 (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
 await UpdateUserByInput(user, input);
 input.MapExtraPropertiesTo(user);
 (await UserManager.UpdateAsync(user)).CheckErrors();
 if (!**input.Password**.IsNullOrEmpty())
 {
 (await UserManager.RemovePasswordAsync(user)).CheckErrors();
 (await UserManager.AddPasswordAsync(user, **input.Password**)).CheckErrors();
 }
 await CurrentUnitOfWork.SaveChangesAsync();
 return ObjectMapper.Map\<IdentityUser, IdentityUserDto>(user);
 }
 [Authorize(IdentityPermissions.Users.Delete)]
 public override async Task DeleteAsync(Guid id)
 {
 if (CurrentUser.Id == id)
 {
 throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
 }
 var user = await UserManager.FindByIdAsync(id.ToString());
 if (user == null)
 {
 return;
 }
 (await UserManager.DeleteAsync(user)).CheckErrors();
 }
 [Authorize(IdentityPermissions.Users.Update)]
 public override async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
 {
 var user = await UserManager.GetByIdAsync(id);
 (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
 await UserRepository.UpdateAsync(user);
 }
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<IdentityUserDto> FindByUsernameAsync(string userName)
 {
 return ObjectMapper.Map\<IdentityUser, IdentityUserDto>(
 await UserManager.FindByNameAsync(userName)
 );
 }
 [Authorize(IdentityPermissions.Users.Default)]
 public override async Task\<IdentityUserDto> FindByEmailAsync(string email)
 {
 return ObjectMapper.Map\<IdentityUser, IdentityUserDto>(
 await UserManager.FindByEmailAsync(email)
 );
 }
 protected override async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input)
 {
 if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase))
 {
 (await UserManager.SetEmailAsync(user, input.Email)).CheckErrors();
 }
 if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase))
 {
 (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors();
 }
 (await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors();
 user.Name = input.Name;
 user.Surname = input.Surname;
 (await UserManager.UpdateAsync(user)).CheckErrors();
 user.SetIsActive(input.IsActive);
 if (input.RoleNames != null)
 {
 (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
 }
 }
}

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, the IdentityUserUpdateDto class has no Password property.

    Because the IdentityUserAppService have a separate method to set the password:

  • User Avatar
    0
    datkinson created

    Hi,

    Yes, the IdentityUserUpdateDto class has no Password property.

    Because the IdentityUserAppService have a separate method to set the password:

    Since which version? I copied the code from the source yesterday.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    The version 7.1.1

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11