skip to content

After AutoMapper became a commercial Lucky Penny product in 15.0, how would you choose a mapping approach for a large ASP.NET Core codebase that uses it everywhere?

level: principalimportance: should knowfreq 30%

answer

  1. RPL-1.5 or a paid licence
  2. enforcement by log messages only
  3. LicenseKey or AUTOMAPPER_LICENSE_KEY
  4. Mapperly: Apache-2.0 source generator
  5. inventory ProjectTo, resolvers and conventions first

basics

~20 s

Treat it as a licence decision plus a migration-cost decision: AutoMapper 15+ is RPL-1.5 or commercial, enforced only by log messages, while Mapperly is an Apache-2.0 source generator. Inventory how the codebase uses AutoMapper, then pay, migrate gradually, or hand-write.

solid answer

~50 s

First the facts as the repository states them: from 15.0 AutoMapper "requires a license"; its LICENSE offers the **Reciprocal Public License 1.5** or a commercial agreement, the key goes in `cfg.LicenseKey` or the `AUTOMAPPER_LICENSE_KEY` / `LUCKYPENNY_LICENSE_KEY` variables, and enforcement is **log messages only**. So nothing breaks at runtime; the question is legal and economic. Then inventory: how many maps, how many use `ProjectTo`, custom resolvers, converters, `ForMember` logic and naming conventions. If the codebase is large and stable and the licence cost is acceptable, paying is a valid answer. Otherwise I would migrate per feature to **Mapperly** — Apache-2.0, a source generator whose strict diagnostics catch unmapped members at build time and which supports `IQueryable` projections — or to hand-written records and expressions where maps are few. Guard the migration with the existing mapping tests and response-level tests.

code

csharp · 12 lines
csharp
// AutoMapper 16: the key is set in code or read from AUTOMAPPER_LICENSE_KEY.
builder.Services.AddAutoMapper(cfg => cfg.LicenseKey = licenseKey, typeof(Program));

// Mapperly 4.3: generated at build time, no runtime registration needed.
[Mapper]
public static partial class EmployeeMapper
{
    [MapperIgnoreSource(nameof(Employee.Salary))]
    public static partial EmployeeDto ToDto(this Employee employee);

    public static partial IQueryable<EmployeeDto> ProjectToDto(this IQueryable<Employee> query);
}

go deeper

for a junior

Know that AutoMapper now needs a licence from 15.0 and that Mapperly is a free source-generated alternative.

for a middle

Explain how each approach catches unmapped members, runtime AssertConfigurationIsValid versus Mapperly's build-time RMG diagnostics, and how each handles IQueryable projections.

for a senior

Plan the inventory and a feature-by-feature migration with equivalence tests and SQL comparisons for ProjectTo replacements.

for a principal

Own the call between paying, migrating and hand-writing, using licence terms as the repository states them, map count, hidden resolver logic and team cost, and record a revisit trigger.

## What actually changed AutoMapper is a convention-based object mapper long used to turn EF Core entities into DTOs in ASP.NET Core apps. Its own repository now records the change: - The **15.0 upgrade guide** opens with "AutoMapper now requires a license" and moves registration to `AddAutoMapper(cfg => cfg.LicenseKey = "...", typeof(Program))`, with the configuration action first in every overload. - The **LICENSE** says use is governed by the **Reciprocal Public License 1.5**, or, for those who do not wish to release their source under it, a commercial Lucky Penny Software licence agreement. - The **licence documentation** says the key can come from code, then `AUTOMAPPER_LICENSE_KEY`, then the shared `LUCKYPENNY_LICENSE_KEY`, and that enforcement is through log messages only — info for valid, warning for missing, error for invalid — with no licence server and no disabled features. So upgrading to 16.2 without a key does not break the app. That is precisely why this is a principal-level question: the forcing function is compliance and budget, not a compiler error. ## Step 1: inventory before choosing The cost of leaving AutoMapper depends on which features the codebase leans on. Count: 1. **Plain maps** where names line up — cheap to replace with anything. 2. **`ProjectTo<TDto>(configuration)`** calls on EF Core queries — need a replacement that also produces expression trees. 3. **`ForMember`, resolvers, value converters, type converters** — business logic hidden in configuration that must move into code. 4. **Flattening and naming conventions** relied on implicitly — `Department.Name` to `DepartmentName`. 5. **Mapping onto existing objects** (`mapper.Map(request, entity)`) in update endpoints. 6. **Tests** that already pin behaviour, such as `AssertConfigurationIsValid()` and response tests. ## Step 2: the options | Option | Licence | Mapping runs | Unmapped members caught | Queryable projection | |---|---|---|---|---| | Stay on AutoMapper 16 with a key | RPL-1.5 or commercial | Runtime, from configuration | `AssertConfigurationIsValid()` in tests (destination side) | `ProjectTo<T>` | | Migrate to Mapperly 4.3 | Apache-2.0 | Generated C# at build time | `RMG012`/`RMG020` diagnostics, warnings by default | `partial IQueryable<TDto>` methods | | Hand-written records, `ToDto()` and expressions | Your code | Plain C# | Compiler, for positional records | `Expression<Func<T, TDto>>` | Mapperly's `[Mapper]` partial classes keep the declarative feel of a mapper library, auto-flatten by name, can map onto existing targets, and show the generated code (with `EmitCompilerGeneratedFiles`). Its queryable projections are expression trees, so some features — object factories, deep cloning, reference handling — do not apply there, which matters if `ProjectTo` maps were complex. ## Step 3: a migration that does not stall - **New code first.** New features use the chosen approach immediately; AutoMapper stops growing. - **Feature by feature.** Replace one profile at a time, keeping the DTOs unchanged so clients see nothing. - **Equivalence tests.** For each migrated map, a test runs old and new mappers over the same populated entity and compares results; delete the old map once green. - **Projections last and measured.** Compare the SQL of `ProjectTo` against the replacement for each query before switching. - **Remove the dependency** when the inventory hits zero, along with any leftover `AutoMapper.Extensions.Microsoft.DependencyInjection` reference, which has been discontinued since 13.0 when `AddAutoMapper` moved into the core package. ## How to decide There is no single right answer, which is the point of the question: - **Pay** when the map count is large, `ProjectTo` and custom resolvers are everywhere, the team knows AutoMapper well, and the licence fits the budget and compliance rules. - **Mapperly** when you want compile-time feedback, readable generated code, a permissive licence and similar ergonomics, and can fund a phased migration. - **Hand-written** when maps are few or already mostly `Select(new Dto(...))`; the strongest compile-time guarantees, the most typing. Whatever you choose, write the decision down with its trigger to revisit — the next licence change, a major upgrade, or a security review that asks where mapping logic lives.

  • What happens at runtime if an ASP.NET Core app upgrades to AutoMapper 16 without a licence key?
    The library logs a warning under the `LuckyPennySoftware.AutoMapper.License` category and otherwise works; its documentation states there is no other enforcement, no licence server and no disabled features. The exposure is contractual, so the decision belongs with whoever owns licence compliance, not with a failing build.
  • Which AutoMapper feature makes a migration to Mapperly most expensive?
    Logic buried in configuration: `ForMember` expressions, custom value resolvers and type converters, and `ProjectTo` maps that rely on them. Plain name-matching maps translate almost one to one into `[Mapper]` partial methods; resolver logic has to become user-implemented mapping methods, and projections must stay expressible as expression trees.

  • AutoMapper 16 stops mapping in production when no licence key is set
  • Mapperly needs a LicenseKey just like AutoMapper since 15.0
  • Mapperly maps by reflection at runtime, so it is slower than AutoMapper
  • AutoMapper.Extensions.Microsoft.DependencyInjection is still the package that provides AddAutoMapper
  • Rewriting every map in one big pull request is the safest migration

Assumes ASP.NET Core 10 with AutoMapper 16.2 (licence changed in 15.0; net10.0 is among its targets) and Mapperly 4.3 (strict mappings since 4.0).