Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Automapper exception when converting object with inheriting members

Automapper exception when converting object with inheriting members

Scheduled Pinned Locked Moved C#
questionworkspace
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    impeham
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups