在没有配置地图的情况下映射相同类型时,AutoMapper 是否会无提示地失败?

Is AutoMapper expected to silently fail when mapping the same type without a map configured?

考虑以下因素:

public class Foo
{
    public int Bar { get; set; }
}

[Test]
void Main()
{
    var mapper = new MapperConfiguration(c => c.AddProfile<EmptyProfile>()).CreateMapper();
    var foo = new Foo(){Bar = 1};
    var baz = new Foo();
    mapper.Map(foo, baz); // does not throw AutoMapperMappingException
    Assert.AreEqual(foo.Bar, baz.Bar); // fails
}

这是使用 10.0.0 的预期行为吗?

根据维护者的说法,这是设计使然。

That's by design. But check https://docs.automapper.org/en/latest/Configuration-validation.html#custom-validations.

来自 https://github.com/AutoMapper/AutoMapper/issues/3480