0

我有,我使用AutoMapper 5.1.1与代码PCL:AutoMapper 5.1.1 MethodAccessException在Windows Phone 8.1(WinRT的)

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

回答

0

过了一段时间我找到解决办法。这是AutoMpper和WP8.1真正的技术问题。

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

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

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