I have added an object mapper in my custom module as below:
public class Auth0UsersManagementModuleAutoMapperProfile : Profile
{
public Auth0UsersManagementModuleAutoMapperProfile()
{
CreateMap<UserDto, UserCreateRequest>()
//.ForMember(dest => dest.Prop, opt => opt.Ignore())
//.ForMember(dest => dest.Prop, opt => opt.MapFrom(src => src.Prop))
.AfterMap((src, dest) => {
dest.Connection = "Username-Password-Authentication";
});
CreateMap<UserDto, UserUpdateRequest>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
.AfterMap((src, dest) => {
dest.Connection = "Username-Password-Authentication";
});
CreateMap<User, UserDto>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId));
CreateMap<User, UserUpdateRequest>();
}
}
The code was working fine and now suddently have stopped working and throwing exception as: "AutoMapperMappingException: Missing type map configuration or unsupported mapping."
Really annoying to see nonderministic code behavior. I have been using AutoMapper since quite some and I'm 100% sure about the mapping is there in code, however, still no luck.
7 Answer(s)
-
0
Yes, already added; as I said it was working like a charm and then suddenly stopped working.
-
0
Can you share where it gives error?
-
0
-
0
Hello, I can't comment because I don't know the content of your classes. There may be a map you forgot to add. Can you share the source code?
-
0
I think you must be interested in the two files:
public class Auth0UsersManagementModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure<Auth0ConnectionOptions>( configuration.GetSection("Auth0")); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var service = context .ServiceProvider .GetRequiredService<Auth0UsersManagementInit>(); service.Initialize(); } }
public class Auth0UsersManagementModuleAutoMapperProfile : Profile { public Auth0UsersManagementModuleAutoMapperProfile() { CreateMap<UserDto, UserCreateRequest>() //.ForMember(dest => dest.Prop, opt => opt.Ignore()) //.ForMember(dest => dest.Prop, opt => opt.MapFrom(src => src.Prop)) .AfterMap((src, dest) => { dest.Connection = "Username-Password-Authentication"; }); CreateMap<UserDto, UserUpdateRequest>() .ForMember(dest => dest.Password, opt => opt.Ignore()) .AfterMap((src, dest) => { dest.Connection = "Username-Password-Authentication"; }); CreateMap<User, UserDto>() .ForMember(dest => dest.Password, opt => opt.Ignore()) .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId)); CreateMap<User, UserUpdateRequest>(); } }
Mapping is called as:
var request = ObjectMapper.Map<UserDto, UserCreateRequest>(user);