Click here to Skip to main content
15,894,405 members
Articles / AutoMapper

Automapper 3.2.1 The Call is Ambiguous Between the Following Methods or Properties

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
12 Feb 2020CPOL 4.9K   1  
A fix for people experiencing the same issue with AutoMapper 3.2.1
Quick error fix for anyone experiencing the same issue. "The call is ambiguous between the following methods or properties." Looks like the syntax for ResolveUsing has changed as of 3.2.0.

Just updated Automapper on my project to 3.2.1. And I got the following error:

The call is ambiguous between the following methods or properties ‘AutoMapper.IMemberConfigurationExpression.ResolveUsing (System.Func<MYASSEMBLY.MYCLASS1,object>)’ and ‘AutoMapper.IMemberConfigurationExpression.ResolveUsing (System.Func<AutoMapper.ResolutionResult,object>)’
C#
Mapper.CreateMap<TaskCreated, Task>()  
.ForMember(x => x.Created, x => x.ResolveUsing(t => DateTime.UtcNow))  
.ForMember(x => x.Modified, x => x.ResolveUsing(t => DateTime.UtcNow))  
.ForMember(x => x.Deleted, x => x.Ignore());  

A quick search finds other people with the same issue.

So there are 2 options.

  1. Use MapFrom:
    C#
    Mapper.CreateMap<TaskCreated, Task>()
    .ForMember(x => x.Created, x => x.MapFrom(t => DateTime.UtcNow))
    .ForMember(x => x.Modified, x => x.MapFrom(t => DateTime.UtcNow))
    .ForMember(x => x.Deleted, x => x.Ignore());
  2. Explicitly tell Automapper what object I’m using in the lambda:
    C#
    Mapper.CreateMap<TaskCreated, Task>()  
    .ForMember(x => x.Created, x => x.ResolveUsing((TaskCreated t) => DateTime.UtcNow))  
    .ForMember(x => x.Modified, x => x.ResolveUsing((TaskCreated t) => DateTime.UtcNow))
    .ForMember(x => x.Deleted, x => x.Ignore()); 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
I have been working in software development for over 16 years, during that time I have worn many hats.

I have worked as a Software Engineer, Architect, Agile Coach and Trainer. I’ve created teams, I’ve lead teams, but my main goal is to help teams build great software and enjoy the process.

I help a whole range of businesses – from startups with just an idea who want to build a team to take that idea into reality and FTSE 100 businesses who need to optimise existing teams – I train, mentor and coach them to success.

If you happen to know of anybody who could benefit from results like this, then please go to my contact page and get in touch.

Owen Davies

Comments and Discussions

 
-- There are no messages in this forum --