Hi,
Currently, I have a profile like this -
CreateMap<PimProductDto, GenericProduct>()
.ForMember(dest => dest.PimId, opt => opt.MapFrom(src => src.ECommerceProductId))
.ForAllOtherMembers(opt => opt.Ignore());
I'd like to map the Dto (which contains all the data I want to add) to a new instance of the product, which I can then process further and ultimately, save to the catalog repo.
However, with my current mapping, I get the following Null Reference error on startup -
Object reference not set to an instance of an object.
at EPiServer.Commerce.Catalog.DataAnnotations.ValidUrlAttribute..ctor(LocalizationService localizationService, UrlSegmentOptions urlSegmentOptions)
at System.RuntimeTypeHandle.CreateCaInstance(RuntimeType type, IRuntimeMethodInfo ctor)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
at AutoMapper.Configuration.MappingExpressionBase.Configure(TypeMap typeMap)
at AutoMapper.ProfileMap.BuildTypeMap(IConfigurationProvider configurationProvider, ITypeMapConfiguration config)
at AutoMapper.ProfileMap.Register(IConfigurationProvider configurationProvider)
at AutoMapper.MapperConfiguration.Seal()
at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
at Client.Web.Startup.CreateMapperConfiguration() in D:\Projects\Client\src\Presentation\Client.Web\Startup.cs:line 48
at Client.Web.Startup.<>c.<ConfigureContainer>b__4_0(ConfigurationExpression x) in D:\Projects\Client\src\Presentation\Client.Web\Startup.cs:line 86
at StructureMap.PipelineGraph.Configure(Action`1 configure)
at StructureMap.Container.Configure(Action`1 configure)
at Client.Web.Startup.ConfigureContainer(ServiceConfigurationContext context) in D:\Projects\Client\src\Presentation\Client.Web\Startup.cs:line 79
at EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key)
at EPiServer.Framework.Initialization.Internal.ModuleNode.ConfigureContainer(ServiceConfigurationContext context)
at EPiServer.Framework.Initialization.InitializationEngine.ConfigureCurrentModules(Boolean final)
at EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions)
at EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction)
at EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType)
at EPiServer.Global..ctor()
at Client.Web.EPiServerApplication..ctor() in D:\Projects\Client\src\Presentation\Client.Web\Global.asax.cs:line 26
at ASP.global_asax..ctor()
This is presumably to do with the destination model being an instance of ProductContent and thus requiring something a bit more specialized for configuring the mapping/profile...
Does anyone have any experience creating a new instance of a page/ProductContent through Automapper? The only thing similar I've been able to find around this issue was this unresolved thread in the dev-to-dev forum - https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2018/7/automapper-custom-resolver-throws-null-exception-in-dependencyresolverinitialization/
I did try QM's suggestion in the thread above but that just resulted in responseless pages with no error message. I imagine that it (or my interpretation of it) broke the routing somehow...
This doesn't seem like anything ground-breaking, so hopefully, this is actually possible?
Any help would be greatly appreciated!
Cheers.