Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug AutoMapper.AutoMapperMappingException

Tags:

automapper

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.

like image 611
Myster Avatar asked Dec 09 '10 00:12

Myster


2 Answers

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

like image 116
Myster Avatar answered Oct 26 '22 10:10

Myster


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.

like image 24
What Would Be Cool Avatar answered Oct 26 '22 11:10

What Would Be Cool