我已经通过NuGet将AutoMapper 3.1.0-ci1027安装到了MVC5网站中。我使用Owain Wraggs' Blog作为我的指南来帮助我。
我的配置文件如下:
然而,当我运行应用程序时,它会在Mapper.Initialize()处崩溃。即使我不在那里包含任何代码,这也会发生。如果我注释掉这行代码,代码就可以正常运行,但是当然,我就不能使用AutoMapper来连接我的对象了。
我看到的错误如下:
[PlatformNotSupportedException: 此类型在此平台上不受支持 IDictionaryFactory]
AutoMapper.Internal.PlatformAdapter.Resolve(Boolean throwIfNotFound)+320 AutoMapper.TypeMapFactory..cctor() +46
[TypeInitializationException: 'AutoMapper.TypeMapFactory'的类型初始值设定项引发了异常。]
AutoMapper.TypeMapFactory..ctor() +0
AutoMapper.Mapper.<.cctor>b__0() +55
AutoMapper.Internal.LazyImpl
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): “AutoMapper.TypeMapFactory”的类型初始值设定项引发了异常。]
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): “AutoMapper.TypeMapFactory”的类型初始值设定项引发了异常。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
任何关于我所遗漏的想法都将不胜感激。
我的配置文件如下:
public static class AutoMapperConfig
{
public static void Initialize()
{
Mapper.Initialize(x =>
{
x.AddProfile<DomainToViewModelMappers>();
x.AddProfile<ViewModelToDomainMappers>();
});
}
}
我正在从Global.asax.cs.Application_Start()中调用Initialize()方法:
AutoMapperConfig.Initialize();
然而,当我运行应用程序时,它会在Mapper.Initialize()处崩溃。即使我不在那里包含任何代码,这也会发生。如果我注释掉这行代码,代码就可以正常运行,但是当然,我就不能使用AutoMapper来连接我的对象了。
我看到的错误如下:
[PlatformNotSupportedException: 此类型在此平台上不受支持 IDictionaryFactory]
AutoMapper.Internal.PlatformAdapter.Resolve(Boolean throwIfNotFound)+320 AutoMapper.TypeMapFactory..cctor() +46
[TypeInitializationException: 'AutoMapper.TypeMapFactory'的类型初始值设定项引发了异常。]
AutoMapper.TypeMapFactory..ctor() +0
AutoMapper.Mapper.<.cctor>b__0() +55
AutoMapper.Internal.LazyImpl
1.get_Value() +79
AutoMapper.Mapper.get_ConfigurationProvider() +34
AutoMapper.Mapper.get_Configuration() +28
AutoMapper.Mapper.Initialize(Action
1 action) +51AIMS.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): “AutoMapper.TypeMapFactory”的类型初始值设定项引发了异常。]
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): “AutoMapper.TypeMapFactory”的类型初始值设定项引发了异常。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
任何关于我所遗漏的想法都将不胜感激。