9

我已经通过 NuGet 将 AutoMapper 3.1.0-ci1027 安装到 MVC5 网站中。我使用Owain Wraggs 的博客作为我的指南来帮助我。

我的配置文件如下所示:

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 操作)+51 C:\Projects\AIMS\AIMS\Mappers\AutoMapperConfig.cs:9 中的 AIMS.Mappers.AutoMapperConfig.Initialize()1.get_Value() +79
AutoMapper.Mapper.get_ConfigurationProvider() +34
AutoMapper.Mapper.get_Configuration() +28
AutoMapper.Mapper.Initialize(Action


AIMS.MvcApplication.Application_Start() 在 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[] 处理程序)+118
System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文)+172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext 上下文)+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 上下文)+254

对我所缺少的任何想法将不胜感激。

4

1 回答 1

19

这是 AutoMapper 中的一个错误,版本 3.1.0-ci1032 包含修复。结果证明支持可移植类库需要更多的工作:)

于 2013-10-17T14:00:39.583 回答