I've installed AutoMapper 3.1.0-ci1027 via NuGet into an MVC5 website. I've used Owain Wraggs' Blog as my guide to help me out.
My config file looks like this:
public static class AutoMapperConfig
{
public static void Initialize()
{
Mapper.Initialize(x =>
{
x.AddProfile<DomainToViewModelMappers>();
x.AddProfile<ViewModelToDomainMappers>();
});
}
}
I am calling the Initialize() method from within Global.asax.cs.Application_Start():
AutoMapperConfig.Initialize();
However, when I run the application it crashes at Mapper.Initialize(). This will happen even if I don't include any code in there. The code runs fine if I comment this line out, but of course, then I'm not using AutoMapper to connect my objects.
The errors I am seeing are as follows:
[PlatformNotSupportedException: This type is not supported on this platform IDictionaryFactory]
AutoMapper.Internal.PlatformAdapter.Resolve(Boolean throwIfNotFound) +320 AutoMapper.TypeMapFactory..cctor() +46[TypeInitializationException: The type initializer for 'AutoMapper.TypeMapFactory' threw an exception.]
AutoMapper.TypeMapFactory..ctor() +0
AutoMapper.Mapper.<.cctor>b__0() +55
AutoMapper.Internal.LazyImpl1.get_Value() +79
1 action) +51
AutoMapper.Mapper.get_ConfigurationProvider() +34
AutoMapper.Mapper.get_Configuration() +28
AutoMapper.Mapper.Initialize(Action
AIMS.Mappers.AutoMapperConfig.Initialize() in c:\Projects\AIMS\AIMS\Mappers\AutoMapperConfig.cs:9
AIMS.MvcApplication.Application_Start() in c:\Projects\AIMS\AIMS\Global.asax.cs:25[HttpException (0x80004005): The type initializer for 'AutoMapper.TypeMapFactory' threw an exception.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936841
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296[HttpException (0x80004005): The type initializer for 'AutoMapper.TypeMapFactory' threw an exception.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Any thoughts on what I'm missing would be greatly appreciated.
This was a bug in AutoMapper, the version 3.1.0-ci1032 contains the fix. Turns out supporting portable class libraries took a bit more work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With