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.
Asked
Active
Viewed 1,372 times
2 Answers
0
Initialize Map in startup.cs
Mapper.Initialize(config => {
config.CreateMap<source, Destination>().ReverseMap();
});
Sᴀᴍ Onᴇᴌᴀ
- 7,890
- 8
- 30
- 58
lazydeveloper
- 812
- 7
- 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();
});
...
}
Henry
- 585
- 7
- 14
-
please add more details in your answer – Alexan Jul 23 '17 at 20:42