Jquery ajax post calls my WebMethod which gets external Web Service content, converts it and return to client.
My class: ConfiguratorModel : List<OptionGroup>
.
Inside Application_Start
: Mapper.CreateMap<choiceList, OptionGroup>()
.
After CreateMap I also run Mapper.AssertConfigurationIsValid()
successfully.
When executing Mapper.Map<List<choiceList>, ConfiguratorModel>(choiceLists)
inside my Converter class, automapper fails and return following error as json to client:
{"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"}
If I move Mapper.CreateMap before Mapper.Map everything works like a charm. But CreateMap is not thread safe, running it each time is a bad workaround. Do you have any idea what I should do? My IIS is btw. running in full trust.