IncludeBase failure in 4.2 (worked in 4.1 and below)
See original GitHub issueSince I upgraded to 4.2, some of my unit tests have been breaking on an AssertConfigurationIsValid. I’ve now managed to cut down my classes to a minimum example necessary to reproduce the problem
Classes:
public abstract class BaseBaseSource { }
public class BaseSource : BaseBaseSource {
public string Foo { get; set; }
}
public class Source : BaseSource { }
public abstract class BaseBaseDest {
public string Foo { get; set; }
}
public class BaseDest : BaseBaseDest { }
public class Dest : BaseDest { }
Mapping Profile:
public class TestProfile : Profile {
protected override void Configure() {
CreateMap<BaseSource, BaseDest>();
CreateMap<Source, Dest>()
.IncludeBase<BaseSource, BaseDest>();
}
}
Unit Test:
[TestMethod]
public void IncludeBase_AutoMapper42() {
var config = new MapperConfiguration(cfg => cfg.AddProfile<TestProfile>());
config.AssertConfigurationIsValid();
}
// [TestMethod]
// public void IncludeBase_AutoMapper41() {
// Mapper.Initialize(cfg => cfg.AddProfile<TestProfile>());
// Mapper.AssertConfigurationIsValid();
// }
Mapping failure error message:
BaseBaseSource -> BaseBaseDest (Destination member list) AutoMapper42.BaseBaseSource -> AutoMapper42.BaseBaseDest (Destination member list)
Unmapped properties: Foo
This test fails in AutoMapper 4.2, but passes in 4.1.1. To reproduce this, it seems to require multiple levels of inheritance, and for the property being matched NOT to be at the same level. For example, if you move Foo fo BaseBaseSource, the property is at the same level and the mapping works.
The problem disappears if you remove .IncludeBase
(which in this case works because Foo is the same on both sides, but my full example requires mapping statements).
Issue Analytics
- State:
- Created 8 years ago
- Comments:22 (10 by maintainers)
Top GitHub Comments
Looks like I’ve found issue related to this one. If it’s not related I’ll create separate one. Interesting that second map works without problems. Minimal example:
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.