简体   繁体   English

Windows Phone 8.1(WinRT)上的AutoMapper 5.1.1 MethodAccessException

[英]AutoMapper 5.1.1 MethodAccessException on Windows Phone 8.1 (WinRT)

I have PCL where I using AutoMapper 5.1.1 with code: 我在PCL中将AutoMapper 5.1.1与代码一起使用:

var mapperConfig = new MapperConfiguration(cfg =>
{
    cfg.AddProfile<TileProfile>();
    cfg.AddProfile<PictureProfile>();
    ...
});

var mapper = mapperConfig.CreateMapper();

Which working well with WinForms but when use my library with Windows Phone 8.1 (WinRT) then I get exception in MapperConfiguration constructor: 哪一种与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: 

I also create blank Windows Phone 8.1 project for test with only Automapper nuget package and this code: 我还创建了空白的Windows Phone 8.1项目,以仅使用Automapper nuget包和以下代码进行测试:

...
public MainPage()
{
    this.InitializeComponent();

    var mapperConfig = new MapperConfiguration(cfg => {});
}
...

with same result. 结果相同。 Do anyone some experience with this issue? 有人对此问题有经验吗? It looks like to me as some bug/internal problem in Automapper. 在我看来,这是Automapper中的一些错误/内部问题。 Thanks 谢谢

After some time I found solution. 一段时间后,我找到了解决方案。 This is really technical problem with AutoMpper and WP8.1. 对于AutoMpper和WP8.1,这确实是技术问题。

Issue will be fixed in next release of AutoMapper. 问题将在下一版本的AutoMapper中修复。

Until new release of AutoMapper can be issue fixed by recompiling AutoMapper from source and removing AllowPartiallyTrustedCallers attribute from AssemblyInfo.cs of AutoMapper. 通过从源重新编译AutoMapper并从AutoMapper的AssemblyInfo.cs中删除AllowPartiallyTrustedCallers属性,直到可以发布新版本的AutoMapper为止。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM