Environment
- ABP Studio Version: 2.1.9
- ABP Framework Version: 10.0.2
- Project Type: Blazor Server
- Mapping Library: Mapperly (migrated from AutoMapper using official migration guide)
Summary
When using ABP Studio to regenerate an entity in a project that was migrated from AutoMapper to Mapperly (following https://abp.io/docs/10.0/release-info/migration-guides/AutoMapper-To-Mapperly), the code generator appends duplicate mapper classes to the bottom of ApplicationMappers.cs instead of detecting and updating the existing Mapperly mapper definitions.
This causes the Mapperly source generator to crash, which cascades into dozens of compilation errors.
Steps to Reproduce
- Start with an ABP project that originally used AutoMapper (e.g., created with ABP Suite pre-10.0)
- Migrate to Mapperly following the official migration guide linked above
- Generate an entity (e.g.,
Product) with all options enabled — verify the project compiles - Open the same entity in ABP Studio and regenerate it (even a minor change like unchecking Excel Export)
- Build the solution
What Happens
ABP Studio appends new mapper classes at the bottom of [ProjectName]ApplicationMappers.cs, even though Mapperly mappers for the same entity already exist earlier in the file. For example, the file ends up with both:
// Original (already existed, ~line 50)
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
public partial class ProductToProductDtoMapper : MapperBase<Product, ProductDto>
{
public override partial ProductDto Map(Product source);
public override partial void Map(Product source, ProductDto destination);
}
// Duplicate appended by ABP Studio (~line 200)
[Mapper]
public partial class ProductToProductDtoMappers : MapperBase<Product, ProductDto>
{
public override partial ProductDto Map(Product source);
public override partial void Map(Product source, ProductDto destination);
}
Note: some duplicates use a slightly different class name (trailing "s"), while others use the exact same class name, producing different error types.
This causes the Mapperly source generator to fail entirely with:
CS8785: Generator 'MapperGenerator' failed to generate source. Exception was of type 'InvalidOperationException' with message 'Sequence contains more than one element'
Because the source generator crashes, none of the ~100 mapper classes in the file receive their generated implementations, producing widespread CS8795 errors ("Partial method must have an implementation part because it has accessibility modifiers").
Additional Issue (same regeneration action)
When unchecking features like "Create user interface" and regenerating, ABP Studio correctly removes those methods from the base interface (e.g., IProductsAppService.cs). However, it does not update or warn about .Extended files that override or call the removed methods, causing additional CS0115 and CS1061 errors.
Expected Behavior
- ABP Studio should detect existing Mapperly mapper classes and update them in-place (or skip if unchanged), not append duplicates
- When removing methods from the base interface/service, ABP Studio should either update
.Extendedfiles or warn the developer about broken references
Suspected Root Cause
I believe ABP Studio's code generator may be looking for AutoMapper-style CreateMap<>() calls in a Profile class to determine whether mappers exist. In a migrated project, those calls have been replaced by Mapperly MapperBase<> classes, which the generator doesn't recognize — so it treats the entity as having no mappers and generates new ones.
Projects created fresh with ABP 10.0+ (where Mapperly is the default) likely don't have this issue because the generator was designed to work with the mapper format it created.
Workaround
Manually revert ApplicationMappers.cs from source control to remove the appended duplicates, then manually fix any .Extended files referencing removed methods.
1 Answer(s)
-
0
This is a known ABP Studio code-generation limitation/bug in Studio 2.1.9 for solutions that were migrated from AutoMapper to Mapperly: during regeneration, Studio fails to recognize the existing Mapperly mapper blocks in
*ApplicationMappers.csand appends new mapper classes instead of updating/reusing the existing ones.- Result: duplicate
[Mapper]classes for the same(TSource, TDestination)pair → Mapperly generator throws CS8785 (Sequence contains more than one element) and then many follow-up partial-method errors.
- Result: duplicate
Workaround (safe + minimal changes):
- After every regeneration, revert the mapper file(s) from source control (as you already do), or manually delete the appended duplicates in
*ApplicationMappers.cs. - To prevent the Mapperly generator from crashing while you’re cleaning up, ensure there is exactly one
MapperBase<TSource, TDestination>(orTwoWayMapperBase<,>) for each mapping pair across the project. - If Studio occasionally appends with a slightly different name (e.g., trailing
s), you still must delete one of them—the Mapperly failure is about duplicated mapping pairs, not just class names.
- After every regeneration, revert the mapper file(s) from source control (as you already do), or manually delete the appended duplicates in
About
.Extendedfiles after feature removal:- Studio updates the “generated/base” interfaces/classes, but it does not automatically refactor your manually-maintained
.Extendedfiles. - Workaround: treat
.Extendedfiles as manual code: after regeneration, remove/adjust overrides and calls to the deleted methods, or revert those.Extendedfiles too (depending on what you want to keep).
- Studio updates the “generated/base” interfaces/classes, but it does not automatically refactor your manually-maintained
Best next step (so this can be fixed):
- Report it to Volosoft via the official channel and include:
- Studio version (2.1.9), Framework version (10.0.2)
- A before/after
ApplicationMappers.csdiff showing the duplicated mapper blocks - The CS8785 error text
- Please contact: https://abp.io/contact
- Report it to Volosoft via the official channel and include:
(Your migration-guide link is reachable and matches the scenario you described: https://abp.io/docs/10.0/release-info/migration-guides/AutoMapper-To-Mapperly)
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.