0
moinahmed created
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.
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
7 Answer(s)
-
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);Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hello, have you looked here? Configuration may be missing.
Your code does not have configuration
Configure<AbpAutoMapperOptions>(options => { //Add all mappings defined in the assembly of the MyModule class options.AddMaps<MyModule>(); });Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
