public abstract class BaseClass
{
public Guid ID { get; set; }
}
public class Thing
{
public BaseClass Entity { get; set; }
}
public class ThingDto
{
public Guid EntityID { get; set; }
}
public class ThingProfile : Profile
{
public ThingProfile()
{
CreateMap<Thing, ThingDto>()
.ReverseMap()
.ForMember(dest => dest.Entity, conf => conf.Ignore());
}
}
We don't want Entity to be mapped at this stage, it stays null and we map it later in parent mapping. We didn't have any issues with this scenario in older versions.
ArgumentException - "Cannot create an instance of abstract type BaseClass".
Mapper.Initialize(x =>
{
x.AddProfile(new ThingProfile());
});
Mapper.Map<Thing>(new ThingDto());
MapFrom-s (including the default unflattening) are reversed now. You can drop ReverseMap and create the maps or ignore the offending path.
C#
CreateMap<Thing, ThingDto>()
.ReverseMap()
.ForPath(d=>d.Entity.ID, o=>o.Ignore()));
See also #2199.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
MapFrom-s (including the default unflattening) are reversed now. You can drop ReverseMap and create the maps or ignore the offending path.
C# CreateMap<Thing, ThingDto>() .ReverseMap() .ForPath(d=>d.Entity.ID, o=>o.Ignore()));