Automapper in a Core 3.1 console app

Skip to first unread message

Jun 5, 2020, 3:51:15 PM6/5/20
to AutoMapper-users
I am trying to use automapper in a console application to do some database maintenance. I figured since I used in my Core web api, I could simply use it in my Core console application.But no matter what I do, it seems like the profile cannot be found. The classes are almost identical. 

I get the following error...

AutoMapper.AutoMapperMappingException: 'Error mapping types
AutoMapperMappingException: Missing type map configuration or unsupported mapping.

I am pasting my code here, in hopes that somebody has tried to implement this in a console app with a service collection.


// Error on this line in my worker service
var genlst = _mapper.Map<IEnumerable<CompanyDatabaseClass>>(myList);

// Setup services

public static IServiceProvider _serviceProvider {

public static void Setup()
var configuration = new ConfigurationBuilder()

//setup our DI
_serviceProvider = new ServiceCollection()
    .AddSingleton<IWork, Work>()
    .AddConsole(options => {
        options.IncludeScopes = true;
    .AddTransient<IWork, Work>()
    .AddAutoMapper((serviceProvider, automapper) =>
        automapper.AddProfile(new AutoMapperProfiles());
    }, typeof(CompanyContext).Assembly)

// The profile class
public class AutoMapperProfiles : Profile
    public AutoMapperProfiles()
        CreateMap<CompanyDatabaseClass, GenericCompany>()
            .ForMember(dest => dest.SICCode, opt => opt.MapFrom(src => src.SicCode))
            .ForMember(dest => dest.SICDesciption, opt => opt.MapFrom(src => src.SicDesciption));

 If anybody has any suggestions I would greatly appreciate them.


Reply all
Reply to author
0 new messages