AutoMapper changed the behavior of AssertConfigurationIsValid()
regarding ignored properties in v12. I can’t find anything in the release notes (https://docs.automapper.org/en/latest/12.0-Upgrade-Guide.html) to explain it.
This simple example passes the test in v11. In v12, it fails saying that NickName
is unmapped, even though I’ve explicitly ignored it. The same issue occurs if I use MapFrom()
instead of Ignore()
.
Is this behavior expected or is it a bug?
var c = new MapperConfiguration(cfg =>
{
cfg.AddProfile<MyMappingProfile>();
});
c.AssertConfigurationIsValid();
////////////////////////////////
public class MyMappingProfile : Profile
{
public MyMappingProfile()
{
// Fails in v11 up to v13.0.2-preview.0.3 because `Address` is unmapped
//CreateMap<Customer, CustomerDTO>();
// Passes in v11 up to v13.0.2-preview.0.3 because `Name and `NickName` are mapped
//CreateMap<Customer, CustomerDTO>(MemberList.Source);
// Passes in v11 because `Name is mapped and `NickName` is ignored
// Fails v12 up to v13.0.2-preview.0.3. The error message says `NickName` is unmapped
CreateMap<Customer, CustomerDTO>(MemberList.Source)
.ForMember(d => d.NickName, o => o.Ignore())
;
}
}
public class Customer
{
public string Name { get; set; }
public string NickName { get; set; }
}
public class CustomerDTO
{
public string Name { get; set; }
public string NickName { get; set; }
public string Address { get; set; }
}