I recently updated AutoMapper from NuGet to the latest version. Previously these mappings (scroll down) worked as desired, but now I get an Exception when the maps are being created:
[ArgumentException: Argument types do not match]
System.Linq.Expressions.Expression.ValidateCoalesceArgTypes(Type left, Type right) +2829369
System.Linq.Expressions.Expression.Coalesce(Expression left, Expression right, LambdaExpression conversion) +79
System.Linq.Expressions.Expression.MakeBinary(ExpressionType binaryType, Expression left, Expression right, Boolean liftToNull, MethodInfo method, LambdaExpression conversion) +4402180
System.Linq.Expressions.Expression.MakeBinary(ExpressionType binaryType, Expression left, Expression right) +18
AutoMapper.Execution.TypeMapPlanBuilder.BuildValueResolverFunc(PropertyMap propertyMap, TypeMapRegistry typeMapRegistry, ParameterExpression srcParam, ParameterExpression destParam, Expression destValueExpr, ParameterExpression ctxtParam) +5559
AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap, IConfigurationProvider configurationProvider, TypeMapRegistry typeMapRegistry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam) +467
AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap pm, IConfigurationProvider configurationProvider, TypeMapRegistry registry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam) +101
AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(TypeMap typeMap, IConfigurationProvider configurationProvider, TypeMapRegistry registry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam, Expression destinationFunc, ParameterExpression destination, Boolean constructorMapping) +406
AutoMapper.Execution.TypeMapPlanBuilder.BuildMapperFunc(TypeMap typeMap, IConfigurationProvider configurationProvider, TypeMapRegistry typeMapRegistry) +2459
AutoMapper.TypeMap.Seal(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider) +555
AutoMapper.MapperConfiguration.Seal(IConfiguration configuration) +3495
AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression, IEnumerable`1 mappers) +385
AutoMapper.MapperConfiguration..ctor(Action`1 configure, IEnumerable`1 mappers) +66
AutoMapper.MapperConfiguration..ctor(Action`1 configure) +72
Here are the mappings. I have a property on my model called Clinch that is an object with a "ClinchChar" property and a "Description" property. The database entity I'm mapping from has a Clinch property that is a string. I need to map the Clinch string on the entity side to an object with that string as ClinchChar and another string as the Description on the model. Where I'm using NullSubstitute is for when the Clinch property on the Entity is null, I want to map it to a new object with default ClinchChar and Description (both will be null strings, but that's okay, as the View doesn't care, but it WOULD throw a NullReferenceException if the object is null - I know I could handle this by checking for a null object, but the view is cleaner this way).
config.CreateMap<Team, TeamEditModel>()
.ForMember(m => m.Clinch, exp => exp.NullSubstitute(new TeamEditClinchModel()));
config.CreateMap<string, TeamEditClinchModel>()
.ForMember(m => m.ClinchChar, exp => exp.MapFrom(s => s))
.ForMember(m => m.Description, exp => exp.MapFrom(s => Consts.ClinchDescriptions[s]));
Again, that code worked in AutoMapper 4.2.1, but does not work in 5.0.2. Should I enter that in GitHub, or is there something that changed and I need to use new syntax?