I was about to start a separate thread, but it seems right in line with this one:
I used to do this in AutoMapper 4 just fine, but I've run into an issue in AutoMapper 5.
UserProfileDTO.Properties is of type JObject.
UserProfile.Properties is a string.
This could would work just fine in AutoMapper 4, but in AutoMapper 5 it breaks at Mapper initialization with the following:
System.ArgumentException was unhandled by user code
Message=Instance property 'Key' is not defined for type 'Newtonsoft.Json.Linq.JToken'
Source=System.Core
StackTrace:
at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
at AutoMapper.Mappers.CollectionMapperExtensions.MapKeyPairValueExpr(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Type sourceType, Type destType, ParameterExpression itemParam, Expression contextParam)
at AutoMapper.Mappers.CollectionMapperExtensions.MapCollectionExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression, Func`2 conditionalExpression, Type ifInterfaceType, MapItem mapItem)
at AutoMapper.Mappers.DictionaryMapper.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
at AutoMapper.Execution.TypeMapPlanBuilder.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap, Expression destinationParameter)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression destinationFunc, Boolean constructorMapping)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda()
at AutoMapper.TypeMap.Seal(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider)
at AutoMapper.Execution.TypeMapPlanBuilder.MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider, TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap, Expression destinationParameter)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression destinationFunc, Boolean constructorMapping)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda()
at AutoMapper.TypeMap.Seal(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider)
at AutoMapper.MapperConfiguration.Seal(IConfiguration configuration)
at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression, IEnumerable`1 mappers)
at AutoMapper.Mapper.Initialize(Action`1 config)
... OMITTED for security ...
InnerException:
I'm not sure what's going on here because it seems to be deep in the bowels of AutoMapper. It's preventing me from upgrading, though, so it looks like I'm going to be on v4 for the time being. Let me know if you have any insights, thanks!