Bart Schelkens Bart Schelkens - 1 month ago 52
C# Question

Automapper Map.CreateMap not used anymore?

I'm using version 5.1.1.0 of AutoMapper.
Previously I was able to the following:

Mapper.CreateMap<SchoolYearDetail, SchoolYearDto>();


But in the version 5.1.1.0 it doesn't exist anymore.
Can anyone tell me what to do?

Answer

Previously AutoMapper was static as per your example, it now wants to be instantiated.

Link below is by the creator of AutoMapper
https://lostechies.com/jimmybogard/2016/01/21/removing-the-static-api-from-automapper/

Here is a snippet if that link stops working.

var config = new MapperConfiguration(cfg => {
  cfg.CreateMap<Source, Dest>();
});

IMapper mapper = config.CreateMapper();
var source = new Source();
var dest = mapper.Map<Source, Dest>(source);

Plenty of other stackoverflow posts related to this:

Automapper says Mapper.Map is obsolete, global mappings?

AutoMapper Migrating from static API

Hope that helps.