Base solution for your next web application
Open Closed

GetUserForEdit AutoMapper error #4652


User avatar
0
kythor created

Hi, couple of months ago I upgraded to ABP 3.4.0 Didnt have any problems until now. Trying to add or update users manually for a tenant. I get his error:

AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
User_0982A06B3D7A322931BE27D128726007A283D673C9DCFF4BE6024F5FF709CCB8 -> UserEditDto

But on another tenant users can still register automatically without a problem.

The UserEditDto hasnt changed since months. What to do?


7 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Check if you have these lines in CustomDtoMapper:

    configuration.CreateMap<User, UserEditDto>()
        .ForMember(dto => dto.Password, options => options.Ignore())
        .ReverseMap()
        .ForMember(user => user.Password, options => options.Ignore());
    
  • User Avatar
    0
    kythor created

    this is whats in CustomDtoMapper:

    private static void CreateMappingsInternal()
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap<User, UserEditDto>()
                    .ForMember(dto => dto.Password, options => options.Ignore())
                    .ReverseMap()
                    .ForMember(user => user.Password, options => options.Ignore()); 
                });
    
            }
    
  • User Avatar
    0
    alper created
    Support Team

    I think you fell into the issue that maps an Entity Framework proxy class to DTO. check out the solution <a class="postlink" href="http://www.jonegerton.com/dotnet/automapper-and-entityframework-proxies-a-workaround/">http://www.jonegerton.com/dotnet/automa ... orkaround/</a>

  • User Avatar
    0
    kythor created

    How did I fell into this? I am using the standard Aspnetzero code, without adjustments...

    this is where the mapper is called: UserAppService > GetUserForEdit

    //Editing an existing user
                    var user = await UserManager.GetUserByIdAsync(input.Id.Value);
    
                    output.User = user.MapTo<UserEditDto>();
                    output.ProfilePictureId = user.ProfilePictureId;
    
                    foreach (var userRoleDto in userRoleDtos)
                    {
                        userRoleDto.IsAssigned = await UserManager.IsInRoleAsync(input.Id.Value, userRoleDto.RoleName);
                    }
    

    then what do I have to change to get this working again?

  • User Avatar
    0
    aaron created
    Support Team

    Try using ObjectMapper:

    ooutput.User = ObjectMapper.Map<UserEditDto>(user);
    
  • User Avatar
    0
    kythor created

    changed it, this is the Error:

    AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
    
    Mapping types:
    User_0982A06B3D7A322931BE27D128726007A283D673C9DCFF4BE6024F5FF709CCB8 -> UserEditDto
    System.Data.Entity.DynamicProxies.User_0982A06B3D7A322931BE27D128726007A283D673C9DCFF4BE6024F5FF709CCB8 -> TIB.TIBtv.Authorization.Users.Dto.UserEditDto
       at lambda_method(Closure , Object , Object , ResolutionContext )
       at AutoMapper.Mapper.AutoMapper.IMapper.Map[TDestination](Object source)
       at TIB.TIBtv.Authorization.Users.UserAppService.d__10.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Abp.Threading.InternalAsyncHelper.d__5`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Abp.Threading.InternalAsyncHelper.d__3`1.MoveNext()
    
  • User Avatar
    0
    alirizaadiyahsi created

    @Kythor, could you please share all related code? (dto, entity, map configuration, app service etc...)