I have PCL where I using AutoMapper 5.1.1 with code:
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:
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:
...
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. Thanks
After some time I found solution. This is really technical problem with AutoMpper and WP8.1.
Issue will be fixed in next release of AutoMapper.
Until new release of AutoMapper can be issue fixed by recompiling AutoMapper from source and removing AllowPartiallyTrustedCallers attribute from AssemblyInfo.cs of AutoMapper.
More info: https://github.com/AutoMapper/AutoMapper/issues/1685