Open Closed

I am getting a lot of warnings RMG020 regarding to the new automapper implementation #10606


User avatar
0
rafael.gonzales created

Hello!

We've been using ABP Framework since many years now and we just recently created a new project with the latest version but we are getting more than 6k+ warnings in this new mapper implementation. I would like your help how to avoid so many warnings

5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member TenantId on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member ParentDepartmentId on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member IsDeleted on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member DeleterId on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member DeletionTime on the mapping source typeDepartment is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member LastModificationTime on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member LastModifierId on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member CreationTime on the mapping source type  Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
5>DemoApplicationMappers.cs(39,5): Warning RMG020 : The member CreatorId on the mapping source type Department is not mapped to any member on the mapping target type HumanResources.DepartmentExcelDto
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • Those RMG020 warnings come from Mapperly’s source generator (used by ABP v10+) and mean: “your mapping exists, but some source members are not mapped to the target type”.
      In your example, Department likely inherits audited / soft-delete / multi-tenant fields (TenantId, IsDeleted, CreationTime, etc.), while DepartmentExcelDto intentionally doesn’t contain them—so Mapperly warns for each such mapping.

    To avoid thousands of warnings, you have these ABP-friendly options:

    1. Tell Mapperly to only require mapping for the target (recommended) Configure your mapper class so it doesn’t require every source member to be mapped:
    using Riok.Mapperly.Abstractions;
       using Volo.Abp.Mapperly;
    
       [Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
       public partial class DemoApplicationMappers
       {
           // your mapping methods
       }
    

    With RequiredMappingStrategy.Target, Mapperly will ensure all destination members are mapped, but it won’t warn just because the source has extra properties (like audit fields).

    1. Ignore specific source members for a specific mapping If you want stricter behavior but silence specific properties, ignore them explicitly on that mapping (example pattern):
    using Riok.Mapperly.Abstractions;
    
       [Mapper]
       public partial class DepartmentExcelMapper
       {
           [MapperIgnoreSource(nameof(Department.TenantId))]
           [MapperIgnoreSource(nameof(Department.ParentDepartmentId))]
           [MapperIgnoreSource(nameof(Department.IsDeleted))]
           [MapperIgnoreSource(nameof(Department.DeleterId))]
           [MapperIgnoreSource(nameof(Department.DeletionTime))]
           [MapperIgnoreSource(nameof(Department.LastModificationTime))]
           [MapperIgnoreSource(nameof(Department.LastModifierId))]
           [MapperIgnoreSource(nameof(Department.CreationTime))]
           [MapperIgnoreSource(nameof(Department.CreatorId))]
           public partial DepartmentExcelDto Map(Department source);
       }
    

    Use this when you want to keep “warn on unmapped source” for most mappings, but selectively suppress noise for DTOs that intentionally exclude infrastructure fields.

    1. (If needed) keep old AutoMapper behavior for your application mappings ABP v10 templates default to Mapperly, but you can still use AutoMapper in your own application if you prefer its “ignore extra source members” behavior. (This is a strategic choice; not usually needed just for warnings if option #1 is acceptable.)

    • https://abp.io/docs/10.2/release-info/migration-guides/AutoMapper-To-Mapperly
    • https://abp.io/docs/10.2/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.

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

    Hi,

    The RMG020 warning is actually expected behavior from Mapperly. By default Mapperly uses RequiredMappingStrategy.Both, meaning every source member is expected to be mapped to a target member (and vice versa). When you map an entity like Department (which inherits ABP audit fields like TenantId, CreationTime, CreatorId, IsDeleted, LastModificationTime, etc.) to a leaner DTO such as DepartmentExcelDto, every extra source field will trigger RMG020. That's why you see 6k+ warnings piling up in one file.

    The fix is to tell Mapperly to only require the target members to be mapped. Just add RequiredMappingStrategy = RequiredMappingStrategy.Target to your [Mapper] attribute:

    [Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
    public partial class DemoApplicationMappers
    {
        public partial DepartmentExcelDto DepartmentToDepartmentExcelDto(Department source);
        // ... your other mappings
    }
    

    This one-line change will silence all of those RMG020 warnings at once, and still keeps the useful warnings (when a target property is missing a mapping).

    If you have several mapper classes and want to set it once for the whole project, you can drop this into any .cs file instead of repeating the attribute on every class:

    [assembly: MapperDefaults(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
    

    This is exactly how ABP's own modules and the latest ABP Studio solution templates are set up. Every generated mapper ships with RequiredMappingStrategy = RequiredMappingStrategy.Target and inherits from MapperBase<TSource, TDestination>, e.g.:

    [Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
    public partial class DepartmentToDepartmentExcelDtoMapper : MapperBase<Department, DepartmentExcelDto>
    {
        public override partial DepartmentExcelDto Map(Department source);
        public override partial void Map(Department source, DepartmentExcelDto destination);
    }
    

    You can check the official migration guide for more context and examples:

    https://abp.io/docs/latest/release-info/migration-guides/automapper-to-mapperly

    Thanks

    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 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.