How do I debug AutoMapper.AutoMapperMappingExcepti

2019-03-27 05:44发布

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.

标签: AutoMapper
2条回答
Lonely孤独者°
2楼-- · 2019-03-27 06:18

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

查看更多
祖国的老花朵
3楼-- · 2019-03-27 06:32

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.

查看更多
登录 后发表回答