Question Details

No question body available.

Tags

c# asp.net-core asp.net-core-webapi automapper

Answers (2)

Accepted Answer Available
Accepted Answer
July 23, 2025 Score: 9 Rep: 55,094 Quality: Expert Completeness: 80%

Assuming that you are using AutoMapper version 13.0 and above, which had been migrated to the core package instead of depending on AutoMapper.Extensions.Microsoft.DependencyInjection package.

The way you are registering the profile(s) is for using the old AutoMapper (before version 13.0).

You should provide the Action for registering the profile:

builder.Services.AddAutoMapper(cfg =>
{
    cfg.AddProfile(new AutoMapperConfigurationProfile());
});

Refer from the official docs, you can also achieve with:

builder.Services.AddAutoMapper(cfg => {}, 
    typeof(AutoMapperConfigurationProfile).Assembly);

// Or builder.Services.AddAutoMapper(cfg => {}, typeof(Program));

which it will scan the assembly and register the profile (class) that implements Profile.

September 29, 2025 Score: 3 Rep: 137 Quality: Medium Completeness: 100%

According to the Automapper 15.0 Upgrade guide, Automapper now requires a license. You can get this by visiting this Lucky Penny Software link and registering using your Google, Microsoft or Github account, you will receive an email verification link.

Once you have verified your account, the rest is pretty straightforward.

  1. Get Automapper

enter image description here

2. Pick your license type based on the need (I picked community for this usecase)

enter image description here

3. Create your one year license.

enter image description here

Once you've done that, you'll proceed to copy your license and set it via the configuration:

services.AddAutoMapper(cfg => {
    cfg.LicenseKey = "";
});

Since the AddAutoMapper overloads now all require the Action parameter this is how you set it up:

// Previous
services.AddAutoMapper(typeof(Program));

// Current services.AddAutoMapper(cfg => cfg.LicenseKey = "", typeof(Program));

BONUS:

The license key can be quite long, I would advise, setting it in your appsettings.json like so:


  "AutoMapper": {
    "LicenseKey": "blehblehbleh"
  },

Then binding (or retrieving) the configuration section from your appsettings.json:

var automapperSettings = builder.Configuration.GetSection("AutoMapper");

Reading your license from the LicenseKey setting of the configuration section:

var autoMapperLicenseKey = automapperSettings["LicenseKey"];

And finally registering AutoMapper in the DI container, configuring it with your license key this way, and scanning the assembly containing Program for profiles

builder.Services.AddAutoMapper(cfg => cfg.LicenseKey = autoMapperLicenseKey, typeof(Program));

That should clear the error and get you on your way.