0

I'm having issues mapping below source and destination classes.

public class Source
{
  public InnerSourceListExtendedClass InnerSourceListExtended {get;set;}
}

public class InnerSourceListExtended : List<InnerSource>
{
}

public class InnerSource{
 public string prop1 {get;set;}
 public string prop1 {get;set;}
}

public class Destination
{
  public List<InnerDestination> InnerDestination {get;set;}
}

public class InnerDestination
{
  public string prop1 {get;set;}
  public string prop1 {get;set;}
}

My current mapping configuration is

CreateMap<Source, Destination>()
ForMember(dest => dest.InnerDestination , opts => opts.MapFrom(src => 
src.InnerSourceListExtended));

Not able to map using above mapping configuration, it is throwing an exception " Error mapping types.\r\n\r\nMapping types:\Source -> Destination."

Any help would be appreciated.

Sushruth
  • 155
  • 2
  • 11
  • I don't think you should subclass `List`: Have you seen this (classic) QA post? https://stackoverflow.com/questions/21692193/why-not-inherit-from-listt – Dai Jun 14 '20 at 02:06
  • 1
    `List` is not compatible with `InnerSourceListExtendedClass` because `InnerSourceListExtendedClass` extends `List` **not** `List`. It's like trying to map `SubclassOfListOfString` from `List`. Do you define a mapping between `InnerSource` and `InnerDestination`? – Dai Jun 14 '20 at 02:10
  • Thank you for quick response, I did not initially defined a mapping between InnerSource and InnerDestination. It worked after defining it. – Sushruth Jun 14 '20 at 02:22

0 Answers0