Open Closed

`AutoMapperMappingException` after migrating from AutoMapper to Mapperly in ABP (.NET 9 → .NET 10) #10330


User avatar
0
pareeks@gccontractor.org created

Issue: AutoMapperMappingException after migrating from AutoMapper to Mapperly in ABP (.NET 9 → .NET 10)

Exception message and stack trace

AutoMapper.AutoMapperMappingException
HResult=0x80131500
Message=Missing type map configuration or unsupported mapping.
Source=AutoMapper
StackTrace: <Cannot evaluate the exception stack trace>

Steps to reproduce

  1. I upgraded an existing ABP.io project from .NET 9 to .NET 10.
  2. As part of the upgrade, ABP is moving from AutoMapper to Mapperly.
  3. I followed the official migration documentation:
  4. I converted all AutoMapper profiles to Mapperly mappers as per the documentation.

Observed behavior

  • When I use ObjectMapper.Map<TSource, TDestination>(), I get the AutoMapperMappingException shown above.
  • However, when I inject the generated Mapperly mapper directly into the consuming class and use it, the mapping works correctly.

Expected behavior

  • I would like to continue using ObjectMapper.Map (ABP’s abstraction) instead of injecting individual Mapperly mapper classes everywhere.

Question

  • How can I correctly configure or register Mapperly mappers so that ObjectMapper.Map works as expected in ABP?
  • Is there any additional setup required to make ObjectMapper resolve Mapperly-based mappers instead of falling back to AutoMapper?

12 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Why you still see AutoMapperMappingException
    • The exception is thrown by AutoMapper, which means that in your app the ABP ObjectMapper is still using AutoMapper as the IAutoObjectMappingProvider.
    • After you converted your profiles to Mapperly mappers, AutoMapper no longer has maps for those types, so calls like ObjectMapper.Map<TSource, TDestination>() fail with:
    AutoMapper.AutoMapperMappingException
      Message=Missing type map configuration or unsupported mapping.
    
    • When you inject and use the Mapperly mapper class directly, it works because that bypasses ABP’s ObjectMapper abstraction entirely.

    To fix this, you must explicitly configure ABP to use Mapperly as the default object mapper.


    1. Solution

    Follow these concrete steps (for ABP 10.0.2):

    A. Switch modules from AutoMapper to Mapperly

    In all projects where you had AutoMapper integration:

    1. csproj references

      • Replace:
    <PackageReference Include="Volo.Abp.AutoMapper" Version="..." />
    

    with:

    <PackageReference Include="Volo.Abp.Mapperly" Version="..." />
    
    1. Module dependencies and usings

      In each module (e.g. YourProjectDomainModule, YourProjectApplicationModule, YourProjectBlazorModule, YourProjectHttpApiHostModule, etc.):

      • Replace:
    using Volo.Abp.AutoMapper;
    
       [DependsOn(
           typeof(AbpAutoMapperModule),
           // ...
       )]
       public class YourProjectXXXModule : AbpModule
       {
           public override void ConfigureServices(ServiceConfigurationContext context)
           {
               context.Services.AddAutoMapperObjectMapper<YourProjectXXXModule>();
    
               Configure<AbpAutoMapperOptions>(options =>
               {
                   options.AddMaps<YourProjectXXXModule>(validate: true);
               });
           }
       }
    

    with:

    using Volo.Abp.Mapperly;
    
       [DependsOn(
           typeof(AbpMapperlyModule),
           // ...
       )]
       public class YourProjectXXXModule : AbpModule
       {
           public override void ConfigureServices(ServiceConfigurationContext context)
           {
               // Register Mapperly object mapper for this module
               context.Services.AddMapperlyObjectMapper<YourProjectXXXModule>();
           }
       }
    

    Notes:

    • Remove all Configure<AbpAutoMapperOptions>(...) blocks.
    • Remove AbpAutoMapperModule from all [DependsOn] attributes.
    • Keep only AbpMapperlyModule (plus your other existing module dependencies).
    B. Set Mapperly as the default object mapper for ObjectMapper.Map

    In at least one root module that is loaded in every app (e.g. your main host / UI / application module), explicitly register the non-generic AddMapperlyObjectMapper so ABP’s default IObjectMapper uses Mapperly:

    using Volo.Abp.Mapperly;
    
    [DependsOn(typeof(AbpMapperlyModule))]
    public class YourProjectHttpApiHostModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            // Make Mapperly the default IAutoObjectMappingProvider used by ObjectMapper.Map<,>()
            context.Services.AddMapperlyObjectMapper();
        }
    }
    

    This is the key step that makes:

    ObjectMapper.Map<TSource, TDestination>(source);
    

    go through Mapperly, not AutoMapper.
    (From the migration guide: “If your application uses Mapperly: context.Services.AddMapperlyObjectMapper();”)

    C. Ensure your Mapperly mappers are properly defined

    Mapperly mappers should look like:

    using Riok.Mapperly.Abstractions;
    using Volo.Abp.Mapperly;
    
    [Mapper] // RequiredMappingStrategy = Target is default in ABP integration
    public partial class MyEntityToMyDtoMapper : MapperBase<MyEntity, MyDto>
    {
        public override partial MyDto Map(MyEntity source);
        public override partial void Map(MyEntity source, MyDto destination);
    }
    

    ABP’s Mapperly integration automatically:

    • Registers all [Mapper] classes in DI.
    • Connects them to ObjectMapper based on <TSource, TDestination>.

    You don’t need to manually wire each mapper to ObjectMapper.

    D. If you use contextual mappers (IObjectMapper<TContext>)

    If somewhere you use a contextual mapper (or ObjectMapperContext), keep the generic registration:

    context.Services.AddMapperlyObjectMapper<MyProjectApplicationModule>();
    

    and in the consumer (e.g., ApplicationService, Blazor page):

    public class MyAppService : ApplicationService
    {
        public MyAppService()
        {
            ObjectMapperContext = typeof(MyProjectApplicationModule);
        }
    
        public Task<MyDto> GetAsync()
        {
            // This now uses Mapperly, via the module-specific object mapper
            return Task.FromResult(ObjectMapper.Map<MyEntity, MyDto>(entity));
        }
    }
    

    This pattern is the same as with AutoMapper, just using Mapperly registration.


    2. Sources

    • Migration guide – “Migrating from AutoMapper to Mapperly”
      (sections Migration Steps and Set Default Mapping ProviderAddMapperlyObjectMapper)
      https://abp.io/docs/10.0/release-info/migration-guides/AutoMapper-To-Mapperly

    • Object-to-object mapping – Mapperly integration & registration (AbpMapperlyModule, AddMapperlyObjectMapper, MapperBase, TwoWayMapperBase)
      https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Which DTOs are you trying to map?

    Can you call the AddMapperlyObjectMapper in your module?

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddMapperlyObjectMapper();
    }
    

    Thanks.

  • User Avatar
    0
    pareeks@gccontractor.org created

    Yes, it's already configured

    [DependsOn(
        typeof(IseCoreDomainModule),
        typeof(IseCoreApplicationContractsModule),
        typeof(AbpDddApplicationModule),
        typeof(AbpMapperlyModule)
        )]
    public class IseCoreApplicationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddMapperlyObjectMapper<IseCoreApplicationModule>();
        }
    }
    

    Trying to do: var filter = ObjectMapper.Map<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>(input); but getting error.

    Here is the configuration for mapperly in file IseCoreApplicationMappers.cs

    [Mapper]
    public partial class HrMissionaryLookupRequestDtoToHrMissionaryLookupFilterMapper
        : MapperBase<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>
    {
        public override partial HrMissionaryLookupFilter Map(HrMissionaryLookupRequestDto source);
    
        public override partial void Map(
            HrMissionaryLookupRequestDto source,
            HrMissionaryLookupFilter destination
        );
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a demo project?

    liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    pareeks@gccontractor.org created

    I can give you the remote access of my system, let me know when you're comfortable to connect Thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the source code?

    Thanks.

  • User Avatar
    0
    pareeks@gccontractor.org created

    Hi, I've shared the application code for one of the module with you. Please have a look. It's a production app, not a test app, so I cannot share the whole source code with you. Thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you set the ObjectMapperContext in the constructor or in the base class?

  • User Avatar
    0
    pareeks@gccontractor.org created

    It worked, thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great 👍

  • User Avatar
    0
    pareeks@gccontractor.org created

    I didn't find this fix in the ABP documentation anywhere. Could you please share the documentation here so that I can have a look. Thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#iobjectmapper-interface

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.2.0-preview. Updated on January 22, 2026, 11:30
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.