AutoMapper Version 9.0.0 - No ConfigureMap() Method on IMappingOperationOptions
Asked Answered
P

1

6

I'm upgrading a Visual Studio 2019 solution's projects from AutoMapper version 8.0.0 to version 9.0.0. There are a number of places in the code that are calling a ConfigureMap() method. Errors in the build output state:

IMappingOperationOptions<TSource, TDestination> does not contain a definition for ConfigureMap and no accessible extension method ConfigureMap...

Here are examples of what the current code looks like:

Mapper.Map(TSource, TDestination, opt => opt.ConfureMap());

Mapper.Map(TSource, TDestination, opt => opt.ConfigureMap().ForMember(dest => dest.someBool, m => m.MapFrom(src => src.someBoolVal));

I've looked at AutoMapper's documentation for upgrading from 8.0.0 to 9.0.0 and see no mention of the ConfigureMap() method being deprecated. However, it's not appearing when I search VS's Object Browser.

I would be most appreciative if anyone can share code for how to accomplish the same functionality in 9.0.0.

Peplum answered 5/1, 2020 at 18:26 Comment(2)
you are going to have to move away from inline mapping. there isnt even documentation for it in v9.Mudfish
To whoever down-voted my question, wouldn't it have been more productive to provide an answer, or a helpful link? A down-vote means the person posing the question does not demonstrate any research effort, or the question is unclear or not useful. I stated part of the research effort I made (AutoMapper documentation, as well as many unmentioned sources), and I tried to be as clear as possible in stating my question and providing code examples.Peplum
R
3

I had the same issue (IMappingOperationOptions not contain a definition for ConfigureMap) and I solved with a different approach.

//Step 1. Create a MapperConfiguration
var customMapConfig = new MapperConfiguration(cfg => {
    cfg.CreateMap<originClass, destClass>()
        .ForMember(dest => dest.FieldA, opt => opt.Ignore())
        .ForMember(dest => dest.FieldB, opt => opt.Ignore());
});

//Step 2. Create the custom Mapper
var customMapper = customMapConfig.CreateMapper();

//Step 3. Execute
customMapper.Map<originClass, destClass>(objOrigin, objDest); 
Rouge answered 14/1, 2020 at 21:34 Comment(1)
Julio Schurt, my apologies for taking so long to reply. Your answer worked great! Thank you.Peplum

© 2022 - 2024 — McMap. All rights reserved.