Automapper exception when converting object with inheriting members
C#
1
Posts
1
Posters
0
Views
1
Watching
-
I have the following objects:
public class Parent { public BaseChild Child {get;set;} } public class BaseChild { } public class ChildOne : BaseChild { public string Member {get;set;} }
"Parent" is mapped to a "Parent2" type from a different module (which has the same member BaseChild).
Mapper.CreateMap(typeof(Parent), typeof(Module2::Parent2)); Mapper.CreateMap(typeof(BaseChild), typeof(Module2::BaseChild)); Mapper.CreateMap(typeof(ChildOne ), typeof(Module2::ChildOne ));
I'm creating a Parent object:
Parent parent = new Parent { Child = new ChildOne { Member = "Test" } }
And try to convert:
object parent2 = Mapper.Map(parent, parent.GetType(), typeof(Module2::Parent2));
I get the following exception from auto mapper: ---------- {AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping. Mapping types: ChildOne -> BaseChild Test.ChildOne -> Test.BaseChild ---------- I need this mapping to work in order to be able to convert objects from a new "Parent2" type (in the 2nd module) to an old one. How do I make it support inherited types of members in a converted class?