Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
12 Feb 2020 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>)’
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:
    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:
    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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here