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

相關問題