Adam Lysák Adam Lysák - 1 year ago 89
C# Question

AutoMapper 5.1.1 MethodAccessException on Windows Phone 8.1 (WinRT)

I have PCL where I using AutoMapper 5.1.1 with code:

var mapperConfig = new MapperConfiguration(cfg =>

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
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.
at AutoMapper.Profile..ctor()
at AutoMapper.Configuration.MapperConfigurationExpression..ctor()
at AutoMapper.MapperConfiguration.Build(Action`1 configure)
at AutoMapper.MapperConfiguration..ctor(Action`1 configure)

I also create blank Windows Phone 8.1 project for test with only Automapper nuget package and this code:

public MainPage()

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

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download