0
votes

I have gone through Google and some of the post here on SO but I am not able to understand why my Automapper setup maps some classes where as not others. I am using .net core 3.1 and AutoMapper 10.0.0

Below is my implementation

FactoryOLTPSystemsEntity : entity class
FactoryOLTPSystems :Domain Class(DTO)

These classes are essentially the same with same properties and there is no change except that they belong to different Namespace.

Service Registration
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

My Mapping class

            //This works perfectly fine 
            CreateMap<Routes, RoutesEntity>()
                .ForMember(dest => dest.integration_id,
                opt => opt.MapFrom(src => Convert.ToString(src.route_id)))
                .ForMember(dest => dest.line_no,
                opt => opt.MapFrom(src => int.Parse(src.dos_line_no.ToString())))
                .ForMember(dest => dest.sub_part_import_src,
                opt => opt.MapFrom(src => double.Parse(src.subimport_path)))
                 .ForMember(dest => dest.dgs_server_id,
                opt => opt.Ignore());

            //This doesnt
            CreateMap<FactoryOLTPSystemsEntity, FactoryOLTPSystems>().ReverseMap();

This is the error I get

Missing type map configuration or unsupported mapping.

Mapping types:
Object -> FactoryOLTPSystems
System.Object -> NameSpace.FactoryOLTPSystems

I not sure if I am missing something. Any help would be appreciated ..Cheers!!

1
@LucianBargaoanu, I am doing the same thing, but its working for some classes and not of others. - user_19240589
Start from scratch and make an example exactly as in the docs. I'm sure it will work. - Lucian Bargaoanu

1 Answers

-1
votes

Not sure why, but this worked, instead of

services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

I used the below code for registering AutoMapper in ConfigureService method

 var mapperConfig = new MapperConfiguration(mc =>
                    {
                        mc.AddProfile(new MappingConfig());
                    });