如何调试AutoMapper.AutoMapperMappingException

时间:2010-12-09 00:20:17

标签: automapper

当我遇到这个异常时,有没有办法从automapper获取更多细节:

AutoMapper.AutoMapperMappingException

通常它会告诉我两种类型的映射,但不是哪个解析器或部分映射失败。

2 个答案:

答案 0 :(得分:16)

简单的回答,就是调用这种方法,最好是在你的单元测试中。

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

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

答案 1 :(得分:2)

修复我的问题的一件事是将此行添加到映射中。

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

不确定为什么这不是默认行为。