How do I debug AutoMapper.AutoMapperMappingException

北城余情 提交于 2019-12-04 19:46:41

问题


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.


回答1:


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




回答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.



来源:https://stackoverflow.com/questions/4393712/how-do-i-debug-automapper-automappermappingexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!