Open Closed

ObjectMapper throwing exception #4555


User avatar
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)
  • User Avatar
    0
    salih created
    Support Team .NET Developer

    Hello, have you looked here? Configuration may be missing.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    moinahmed created

    Yes, already added; as I said it was working like a charm and then suddenly stopped working.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    salih created
    Support Team .NET Developer

    Can you share where it gives error?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    moinahmed created

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    salih created
    Support Team .NET Developer

    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?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    moinahmed created

    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)
  • User Avatar
    0
    salih created
    Support Team .NET Developer

    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)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.