![](/img/trans.png)
[英]MethodAccessException with Reflection on Windows Phone 7
[英]AutoMapper 5.1.1 MethodAccessException on Windows Phone 8.1 (WinRT)
我在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中的一些错误/内部问题。 谢谢
一段时间后,我找到了解决方案。 对于AutoMpper和WP8.1,这确实是技术问题。
问题将在下一版本的AutoMapper中修复。
通过从源重新编译AutoMapper并从AutoMapper的AssemblyInfo.cs中删除AllowPartiallyTrustedCallers属性,直到可以发布新版本的AutoMapper为止。
更多信息: https : //github.com/AutoMapper/AutoMapper/issues/1685
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.