LuckyPennySoftware/AutoMapper · error · AutoMapperMappingException
Error building member mapping strategy.
Error message
Error building member mapping strategy.
What it means
Thrown during execution-plan compilation when building the expression for a ForMember property mapping fails with a non-AutoMapperConfigurationException error. The AddPropertyMaps method catches the inner exception and rethrows it as AutoMapperMappingException wrapping the PropertyMap context. This occurs at configuration-build time when the execution plan is compiled.
Source
Thrown at src/AutoMapper/Execution/TypeMapPlanBuilder.cs:314
if (!propertyMap.CanResolveValue)
{
continue;
}
try
{
var property = TryMemberMap(propertyMap,
CreatePropertyMapFunc(propertyMap, _destination, propertyMap.DestinationMember));
if (_typeMap.ConstructorParameterMatches(propertyMap.DestinationName))
{
property = _initialDestination.IfNullElse(_configuration.Default(property.Type), property);
}
actions.Add(property);
}
catch (Exception e) when (e is not AutoMapperConfigurationException)
{
throw new AutoMapperMappingException("Error building member mapping strategy.", e, propertyMap);
}
}
}
private Expression TryPathMap(PathMap pathMap)
{
var destination =
((MemberExpression)_configuration.ConvertReplaceParameters(pathMap.DestinationExpression, _destination))
.Expression;
var pathMapFunc = CreatePropertyMapFunc(pathMap, destination, pathMap.MemberPath.Last);
_expressions.Clear();
foreach (var member in destination.GetMemberExpressions())
{
var setter = GetSetter(member);
var ifNull = setter == null
? Throw(Constant(new NullReferenceException($"{member} cannot be null because it's used by ForPath.")),
member.Type)
: (Expression)Assign(setter, ObjectFactory.GenerateConstructorExpression(member.Type, _configuration));View on GitHub (pinned to dfa6dd587c)
Solutions
- Inspect the InnerException of the AutoMapperMappingException for the precise failure.
- Add a CreateMap or custom type converter (ConvertUsing) for the member's source-to-destination type pair.
- Fix the MapFrom lambda so it returns the correct destination member type.
- If the member is complex, consider a custom IValueResolver.
Example fix
// before — incompatible member types, no converter
CreateMap<Source, Dest>()
.ForMember(d => d.Amount, opt => opt.MapFrom(s => s.AmountString));
// Amount is decimal, AmountString is string
// after — add explicit conversion in MapFrom
CreateMap<Source, Dest>()
.ForMember(d => d.Amount, opt => opt.MapFrom(s => decimal.Parse(s.AmountString))); Defensive patterns
Strategy: try-catch
Try / catch
try
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Dest>()
.ForMember(d => d.Amount, opt => opt.MapFrom(s => s.AmountValue)));
config.CompileMaps();
}
catch (AutoMapperMappingException ex) when (ex.Message.Contains("member mapping strategy"))
{
// ex.InnerException has the real error; ex.MemberMap identifies the failing property
logger.LogError(ex.InnerException, "Member plan build failed for {Member}", ex.MemberMap?.DestinationMember);
} Prevention
- Ensure source and destination member types are compatible or register a converter/type map for them.
- Use AssertConfigurationIsValid in tests to detect plan-building failures early.
- Always inspect the InnerException to find the precise type mismatch or resolver error.
- Prefer strongly-typed MapFrom lambdas so the compiler checks type compatibility.
When it happens
Trigger: A ForMember configuration whose resolver, MapFrom expression, or type conversion produces an invalid expression tree — e.g., source member type and destination member type are incompatible with no registered type map or converter, or a custom resolver returns the wrong type.
Common situations: Type mismatch between source and destination member types with no implicit conversion or registered type map; invalid custom resolver returning incompatible types; null-reference in a MapFrom lambda that fails during expression compilation.
Related errors
- Error building path mapping strategy.
- Error building constructor parameter mapping strategy.
- Unexpected member.
- Expression '{lambdaExpression}' must resolve to top-level me
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/71096b7278a819c4.
Report an issue: GitHub.