Open Closed

AutoMapper not working in Blazor #10243


User avatar
0
samirmustafayev created

Hi Abp Team,

I have an issue with AutoMapperProfile. I am using AutoMapper after update to version 10.0.1 i am getting an issue with it. It tells me to use Mapperly. In application layer it works but in Blazor it asks to use mapperly.

How can I resolve this issue?


6 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • What changed in v10.0.1

      • ABP Framework modules switched their default object mapper from AutoMapper to Mapperly in v10. You can still use AutoMapper in your own application layers, but new ABP templates and modules favor Mapperly. This is why you see guidance “use Mapperly,” especially in UI layers like Blazor.
    • Why it “works in Application layer but not in Blazor”

      • Your Application layer likely still references and configures Volo.Abp.AutoMapper and your AutoMapper profiles. However, your Blazor project was created/updated to v10 where the UI integration uses Mapperly by default. If the Blazor project no longer references Volo.Abp.AutoMapper or doesn’t register your AutoMapper profiles, AutoMapper-based mappings won’t be available there.
    • Two supported ways to resolve

      Option A — Keep using AutoMapper everywhere (quickest to keep existing profiles)

      1. Add the AutoMapper integration in all layers that need it (including Blazor):
        • Add package references to the Blazor project:
          • Volo.Abp.AutoMapper
          • AutoMapper
          • AutoMapper.Extensions.Microsoft.DependencyInjection
      2. Ensure your Blazor module depends on AbpAutoMapperModule and registers your profiles:
    using Volo.Abp;
         using Volo.Abp.AutoMapper;
         using Volo.Abp.Modularity;
    
         [DependsOn(
             typeof(AbpAutoMapperModule)
         )]
         public class MyProjectBlazorModule : AbpModule
         {
             public override void ConfigureServices(ServiceConfigurationContext context)
             {
                 context.Services.AddAutoMapperObjectMapper<MyProjectBlazorModule>();
    
                 Configure<AbpAutoMapperOptions>(options =>
                 {
                     // Add your AutoMapper profiles that contain CreateMap<,>() definitions
                     options.AddMaps<MyProjectApplicationModule>(validate: true);
                     options.AddMaps<MyProjectBlazorModule>(validate: true);
                 });
             }
         }
    
    1. Make sure your AutoMapper Profile classes are in assemblies scanned above (e.g., Application and Blazor projects if you keep profiles there).
    2. If you previously removed Volo.Abp.AutoMapper due to the upgrade, restore it in the .csproj and module DependsOn.

    Option B — Migrate to Mapperly (recommended for ABP v10+)

    1. Replace AutoMapper integration with Mapperly across the solution:
      • In all projects, replace Volo.Abp.AutoMapper with Volo.Abp.Mapperly (csproj).
      • In code, replace:
        • using Volo.Abp.AutoMapper; → using Volo.Abp.Mapperly;
        • AbpAutoMapperModule → AbpMapperlyModule
        • AddAutoMapperObjectMapper → AddMapperlyObjectMapper
        • Remove Configure<AbpAutoMapperOptions> blocks.
    2. Convert your AutoMapper Profile mappings to Mapperly mappers using partial classes with [Mapper] and Map/ReverseMap methods. Example:
    using Riok.Mapperly.Abstractions;
         using Volo.Abp.Mapperly;
    
         [Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
         public partial class MyEntityToDtoMapper : MapperBase<MyEntity, MyEntityDto>
         {
             public override partial MyEntityDto Map(MyEntity source);
             public override partial void Map(MyEntity source, MyEntityDto destination);
         }
    
    1. Register Mapperly in each layer (including Blazor) that needs mappings:
    using Volo.Abp;
         using Volo.Abp.Mapperly;
         using Volo.Abp.Modularity;
    
         [DependsOn(typeof(AbpMapperlyModule))]
         public class MyProjectBlazorModule : AbpModule
         {
             public override void ConfigureServices(ServiceConfigurationContext context)
             {
                 context.Services.AddMapperlyObjectMapper<MyProjectBlazorModule>();
             }
         }
    
    1. Build to let source generators produce mapping implementations. Fix any missing attributes (e.g., MapProperty, MapperIgnoreTarget) and AfterMap custom logic.
    • Practical recommendation
      • If you need a fast fix to keep your existing profiles: follow Option A and re-enable AutoMapper in the Blazor project.
      • If you can invest a bit of time for the future-proof path: follow Option B and migrate to Mapperly using the guide below.
    1. Sources
    • ABP 10 migration and Mapperly adoption:
      • https://abp.io/docs/10.0/release-info/migration-guides/abp-10-0
      • https://abp.io/docs/10.0/release-info/migration-guides/AutoMapper-To-Mapperly
    • Background and examples (community/ABP context):
      • https://abp.io/community/articles/best-free-alternatives-to-automapper-in-net-l9f5ii8s

    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

    Can you add code below to your Blazor project?

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

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    This code is there, but still i am getting error when Actions->Edit

    blazor.web.js:1 [2025-12-20T05:02:32.742Z] Error: Volo.Abp.AbpException: No object mapping was found for the specified source and destination types.
    
    Mapping attempted:
    TaskGroupDto -> TaskGroupUpdateDto
    Payhas.TaskManagement.TaskGroups.TaskGroupDto -> Payhas.TaskManagement.TaskGroups.TaskGroupUpdateDto
    
    How to fix:
    Define a mapping class for these types:
       - Use MapperBase<TSource, TDestination> for one-way mapping.
       - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping.
    
    For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration
       at Volo.Abp.Mapperly.MapperlyAutoObjectMappingProvider.Map[TSource,TDestination](Object source)
       at Volo.Abp.ObjectMapping.DefaultObjectMapper.AutoMap[TSource,TDestination](Object source)
       at Volo.Abp.ObjectMapping.DefaultObjectMapper.Map[TSource,TDestination](TSource source)
       at Payhas.TaskManagement.Blazor.Pages.TaskManagement.TaskGroups.OpenEditTaskGroupModalAsync(TaskGroupDto input) in D:\Billing_Platform\modules\payhas.taskmanagement\src\Payhas.TaskManagement.Blazor\Pages\TaskManagement\TaskGroups.razor.cs:line 218
       at Payhas.TaskManagement.Blazor.Pages.TaskManagement.TaskGroups.<>c__DisplayClass107_0.<<BuildRenderTree>b__41>d.MoveNext() in D:\Billing_Platform\modules\payhas.taskmanagement\src\Payhas.TaskManagement.Blazor\Pages\TaskManagement\TaskGroups.razor:line 151
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
       at Volo.Abp.BlazoriseUI.Components.EntityAction`1.ActionClickedAsync()
       at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
       at Blazorise.DropdownItem.ClickHandler()
       at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
       at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
    

    this is the code :

    public class TaskManagementBlazorModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAutoMapperObjectMapper&lt;TaskManagementBlazorModule&gt;();
    
            Configure&lt;AbpAutoMapperOptions&gt;(options =>
            {
                options.AddProfile&lt;TaskManagementBlazorAutoMapperProfile&gt;(validate: true);
            });
    
            Configure&lt;AbpNavigationOptions&gt;(options =>
            {
                options.MenuContributors.Add(new TaskManagementMenuContributor());
            });
    
            Configure&lt;AbpRouterOptions&gt;(options =>
            {
                options.AdditionalAssemblies.Add(typeof(TaskManagementBlazorModule).Assembly);
            });
        }
    
    public class TaskManagementBlazorAutoMapperProfile : Profile
    {
        public TaskManagementBlazorAutoMapperProfile()
        {
            /* You can configure your AutoMapper mapping configuration here.
             * Alternatively, you can split your mapping configurations
             * into multiple profile classes for a better organization. */
    
            CreateMap&lt;TaskGroupDto, TaskGroupUpdateDto&gt;();
    
            CreateMap&lt;TaskTypeDto, TaskTypeUpdateDto&gt;();
    
            CreateMap&lt;TaskItemDto, TaskItemUpdateDto&gt;();
        }
    }
    

    and here is application configuration :

    public class TaskManagementApplicationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAutoMapperObjectMapper&lt;TaskManagementApplicationModule&gt;();
            Configure&lt;AbpAutoMapperOptions&gt;(options =>
            {
                options.AddMaps&lt;TaskManagementApplicationModule&gt;(validate: true);
            });
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    If you specify the mapper context (TaskManagementBlazorModule), you must specify it when using it.

    context.Services.AddAutoMapperObjectMapper<TaskManagementBlazorModule>();

    Check your base class and set the ObjectMapperContext = typeof(TaskManagementBlazorModule);

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    It solved the issue.

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great 👍

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.1.0-preview. Updated on December 17, 2025, 07:08
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.