我有 PCL,我使用 AutoMapper 5.1.1 和代码:
var mapperConfig = new MapperConfiguration(cfg =>
{
cfg.AddProfile<TileProfile>();
cfg.AddProfile<PictureProfile>();
...
});
var mapper = mapperConfig.CreateMapper();
哪个与 WinForms 配合得很好,但是当我的库与 Windows Phone 8.1 (WinRT) 一起使用时,我在MapperConfiguration构造函数中遇到异常:
System.MethodAccessException was unhandled by user code
HResult=-2146233072
Message=Attempt by security transparent method 'AutoMapper.Profile..ctor()' to access security critical method 'System.Collections.Concurrent.ConcurrentDictionary`2<System.__Canon,System.__Canon>..ctor()' failed.
Source=AutoMapper
StackTrace:
at AutoMapper.Profile..ctor()
at AutoMapper.Configuration.MapperConfigurationExpression..ctor()
at AutoMapper.MapperConfiguration.Build(Action`1 configure)
at AutoMapper.MapperConfiguration..ctor(Action`1 configure)
InnerException:
我还创建了空白的 Windows Phone 8.1 项目以仅使用 Automapper nuget 包和以下代码进行测试:
...
public MainPage()
{
this.InitializeComponent();
var mapperConfig = new MapperConfiguration(cfg => {});
}
...
结果相同。有没有人有这个问题的经验?在我看来,它是 Automapper 中的一些错误/内部问题。谢谢