我有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中的一些错误/内部问题。感谢
答案 0 :(得分:0)
过了一段时间我找到了解决方案。这是AutoMpper和WP8.1的真正技术问题。
问题将在下一版AutoMapper中修复。
通过从源代码重新编译AutoMapper并从AutoMapper的AssemblyInfo.cs中删除 AllowPartiallyTrustedCallers 属性,可以解决AutoMapper的新版本问题。