0

我有 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 中的一些错误/内部问题。谢谢

4

1 回答 1

0

一段时间后,我找到了解决方案。这确实是 AutoMpper 和 WP8.1 的技术问题。

问题将在 AutoMapper 的下一版本中修复。

直到可以通过从源重新编译 AutoMapper 并从 AutoMapper 的 AssemblyInfo.cs 中删除AllowPartiallyTrustedCallers属性来修复 AutoMapper 的新版本。

更多信息:https ://github.com/AutoMapper/AutoMapper/issues/1685

于 2016-11-23T22:06:41.657 回答