1

I have a really strange problem, which I can't explain. See this Map for an AutomapperProfile:

            CreateMap<BO, AbstractDto>()
            .Include<BO, ConcreteDto1>()
            .Include<BO, ConcreteDto2>()
            .ForMember(d...));

I have the same Business-Object and one abstract Dto with two concrete implementations. If I just use this, the AutoMapper only recognizes the first Include, but ignores the second one and throws an exception. I verified this by first including the ConcreteDto2, which caused this mapping to work and the ConcreteDto1 to throw.

The closest answer I found was: AutoMapper -- inheritance mapping not working, same source, multiple destinations but in my case it definitely only takes the first Include.

Is this the same problem as in the Thread, or is there another problem? If yes so, is there a convinient solution arround without code duplicating?

Thanks in advance

Matthias

Community
  • 1
  • 1
Matthias Müller
  • 3,336
  • 3
  • 33
  • 65

1 Answers1

2

This is a bug in AutoMapper 4.0, with a PR open to fix it for 4.1. For now, you need to use Mapper.Initialize instead of Mapper.CreateMap to perform initial configuration.

Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69