12

Is there some way to get some more detail from automapper when I get this exception:

AutoMapper.AutoMapperMappingException

Often it will tell me the 2 types of the mapping, but not which resolver or part of the mapping is failing.

Myster
  • 17,704
  • 13
  • 64
  • 93

2 Answers2

19

Simple answer, is to call this method, preferably in your unit test.

// ensure your configuration mappings are loaded first (bootstrapper)
Mapper.AssertConfigurationIsValid();

see: http://docs.automapper.org/en/stable/Getting-started.html#how-do-i-test-my-mappings

Myster
  • 17,704
  • 13
  • 64
  • 93
  • https://stackoverflow.com/users/2734502/csk Noticed my link was out of date (he could not comment to suggests this link: https://automapper.readthedocs.io/en/latest/Getting-started.html# ) I did a google and found the one I've used in my answer which looks like an official domain, and which seems to contain the same content. – Myster Nov 28 '18 at 00:14
2

One thing that fixed my problem was adding this line to the mapping.

.ForAllMembers(op=>op.Condition(x=>!x.IsSourceValueNull));

Not sure why this isn't the default behavior.

What Would Be Cool
  • 6,204
  • 5
  • 45
  • 42
  • 2
    We got nullable types so it is default to map them too sometimes :) Default is just to map all things, even nulls. – Jacob Sobus Jan 20 '16 at 15:01