Jquery ajax post 调用我的 WebMethod,它获取外部 Web 服务内容,将其转换并返回给客户端。
我的班级:ConfiguratorModel : List<OptionGroup>
。
里面Application_Start
:Mapper.CreateMap<choiceList, OptionGroup>()
。
在 CreateMap 之后,我也Mapper.AssertConfigurationIsValid()
成功运行。
在我的 Converter 类中执行时Mapper.Map<List<choiceList>, ConfiguratorModel>(choiceLists)
,automapper 失败并将以下错误作为 json 返回给客户端:
{"Message":"TryingtomapSystem.Collections.Generic.List`1[[Constructor.OFML.Services.Basket.choiceList,Constructor.OFML,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null]]toConstructor.OFML.ConfiguratorModel.\nExceptionoftype\u0027AutoMapper.AutoMapperMappingException\u0027wasthrown.","StackTrace":"atAutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContextcontext)\r\natAutoMapper.MappingEngine.Map(Objectsource,TypesourceType,TypedestinationType)\r\natAutoMapper.MappingEngine.Map[TSource,TDestination](TSourcesource)\r\natAutoMapper.Mapper.Map[TSource,TDestination](TSourcesource)\r\natConstructor.OFML.ConfiguratorConverter.ConvertToConfiguratorModel(List`1choiceLists)inc:\\EPiServer\\Sites\\bouvet_sbe\\Constructor\\trunk7\\libraries\\Constructor.FOML\\ConfiguratorConverter.cs:line58\r\natConstructor.OFML.ConfiguratorConverter.BuildConfiguratorModel(List`1choiceLists,articleDataarticleData)inc:\\EPiServer\\Sites\\bouvet_sbe\\Constructor\\trunk7\\libraries\\Constructor.FOML\\ConfiguratorConverter.cs:line68\r\natConstructor.OFML.ConfiguratorConverter.BuildConfiguratorResultModel(List`1choiceLists,articleDataarticleData,StringimageUrl)inc:\\EPiServer\\Sites\\bouvet_sbe\\Constructor\\trunk7\\libraries\\Constructor.FOML\\ConfiguratorConverter.cs:line90\r\natConstructor.OFML.OfmlService.GetConfigurationResult(StringsessionId,StringarticleId)inc:\\EPiServer\\Sites\\bouvet_sbe\\Constructor\\trunk7\\libraries\\Constructor.FOML\\OfmlService.cs:line89\r\natConstructor.Services.ConfiguratorService.GetInitialJson(StringsessionId,StringarticleId)inc:\\EPiServer\\Sites\\bouvet_sbe\\Constructor\\trunk7\\www\\Services\\ConfiguratorService.asmx.cs:line32","ExceptionType":"AutoMapper.AutoMapperMappingException"}
如果我在 Mapper.Map 之前移动 Mapper.CreateMap 一切都会像魅力一样。但是 CreateMap 不是线程安全的,每次运行它都是一个不好的解决方法。你知道我应该怎么做吗?我的 IIS 是顺便说一句。完全信任地运行。