Error compiling AutoMapper.ForMember method. Invalid Overload

I am trying to map using Automapper

Here is my current mapping:

Mapper.CreateMap(Of NameAddress, PersonalDetails)() _ .ForMember(Function(dest) dest.Forenames, Function(opt) opt.MapFrom(Function(src) src.Forename)) _ .ForMember(Function(dest) dest.TelephoneNumber, Function(opt) opt.MapFrom(Function(src) src.TelephoneNo1)) _ .ForMember(Function(dest) dest.MobileNumber, Function(opt) opt.MapFrom(Function(src) src.MobilePhoneNo)) _ .ForMember(Function(dest) dest.NationalInsuranceNumber, Function(opt) opt.MapFrom(Function(src) src.NINo)) _ .ForMember(Function(dest) dest.DateOfBirth, Function(opt) opt.MapFrom(Function(src) src.BirthDate)) 

So, from the original NameAddress object, I want to map the PersonalDetails destination object. The remaining properties of both the source and destination are the same, so the associations are not explicitly defined.

However, when I try to compile using this mapping, I get the following compile time error.

 Overload resolution failed because no accessible 'ForMember' can be called with these arguments: 'Public Function ForMember(name As String, memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Lambda expression cannot be converted to 'String' because 'String' is not a delegate type. 'Public Function ForMember(name As String, memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Expression does not produce a value. 'Public Function ForMember(destinationMember As System.Linq.Expressions.Expression(Of System.Func(Of Core.TaxiLicensing.PersonalDetails, Object)), memberOptions As System.Action(Of AutoMapper.IMemberConfigurationExpression(Of Infrastructure.NameAddress))) As AutoMapper.IMappingExpression(Of Infrastructure.NameAddress, Core.TaxiLicensing.PersonalDetails)': Expression does not produce a value. 

What am I missing? Is the display incorrect? It appears that the user is trying to overload a function that I do not intend to use.

+8
automapper
source share
2 answers

My mistake...

Should have used:

 Mapper.CreateMap(Of NameAddress, PersonalDetails)() _ .ForMember(Function(dest) dest.Forenames, Sub(opt) opt.MapFrom(function(src) src.Forename)) _ .ForMember(Function(dest) dest.TelephoneNumber, sub(opt) opt.MapFrom(function(src) src.TelephoneNo1)) _ .ForMember(Function(dest) dest.MobileNumber, Sub(opt) opt.MapFrom(function(src) src.MobilePhoneNo)) _ .ForMember(Function(dest) dest.NationalInsuranceNumber, sub(opt) opt.MapFrom(function(src) src.NINo)) _ .ForMember(Function(dest) dest.DateOfBirth, Sub(opt) opt.MapFrom(function(src) src.BirthDate)) 
+15
source share
  Mapper.CreateMap(Of Category, DTOCategory)() _ .ForMember(Function(c) c.ID, Sub(opt) opt.Ignore()) _ .ForMember(Function(c) c.NAME, Sub(opt) opt.Ignore()) 
0
source share

All Articles