0

I am using ProjectTo function of AutoMapper 5.2.0 in asp.net core. I have already initialized my mappings at startup class. But it is throwing exception : Mapping not initialized.

Anit
  • 33
  • 8

2 Answers2

0

Initialize Map in startup.cs

Mapper.Initialize(config => {
    config.CreateMap<source, Destination>().ReverseMap();      
});
Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
lazydeveloper
  • 891
  • 10
  • 20
0

You are missing the initialization, however, I would recommend you to use the configuration by profile approach especially if you are interested in testing you code.

Could you please add more details to the question?

This is a typical configuration with static methods

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        ...

        AutoMapper.Mapper.Initialize(cfg =>
        {
            cfg.CreateMap<ClassEntity, ClassDto>().ReverseMap();
        });

         ...
    }

Here you can find a good answer step by step

Henry
  • 785
  • 9
  • 17