LuckyPennySoftware/AutoMapper · error · ArgumentOutOfRangeException
Only member accesses are allowed. {destinationMember}
Error message
Only member accesses are allowed. {destinationMember} What it means
Thrown by ForPath when the destination lambda expression is not a pure member-access chain (consecutive property or field accesses starting from the lambda parameter). The method calls IsMemberPath which walks the expression body via GetChain; any node that is not a MemberExpression causes the check to return false, and ForPath throws ArgumentOutOfRangeException.
Source
Thrown at src/AutoMapper/Configuration/MappingExpression.cs:63
internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty, Action<IMemberConfigurationExpression> memberOptions)
{
MemberConfigurationExpression expression = new(destinationProperty, SourceType);
MemberConfigurations.Add(expression);
memberOptions(expression);
return expression;
}
}
public class MappingExpression<TSource, TDestination> : MappingExpressionBase<TSource, TDestination, IMappingExpression<TSource, TDestination>>,
IMappingExpression<TSource, TDestination>, IProjectionExpression<TSource, TDestination>
{
public MappingExpression(MemberList memberList, bool projection) : base(memberList) => Projection = projection;
public MappingExpression(MemberList memberList, TypePair types) : base(memberList, types) { }
public IMappingExpression<TSource, TDestination> ForPath<TMember>(Expression<Func<TDestination, TMember>> destinationMember,
Action<IPathConfigurationExpression<TSource, TDestination, TMember>> memberOptions)
{
if (!destinationMember.IsMemberPath(out var chain))
{
throw new ArgumentOutOfRangeException(nameof(destinationMember), "Only member accesses are allowed. " + destinationMember);
}
PathConfigurationExpression<TSource, TDestination, TMember> expression = new(destinationMember, chain);
var firstMember = expression.MemberPath.First;
var firstMemberConfig = GetDestinationMemberConfiguration(firstMember);
if (firstMemberConfig == null)
{
IgnoreDestinationMember(firstMember, ignorePaths: false);
}
MemberConfigurations.Add(expression);
memberOptions(expression);
return this;
}
public IMappingExpression<TSource, TDestination> ForMember<TMember>(Expression<Func<TDestination, TMember>> destinationMember, Action<IMemberConfigurationExpression<TSource, TDestination, TMember>> memberOptions)
{
var memberInfo = ReflectionHelper.FindProperty(destinationMember);
return ForDestinationMember(memberInfo, memberOptions);
}
private void IncludeMembersCore(LambdaExpression[] memberExpressions) => TypeMapActions.Add(tm => tm.IncludedMembers = memberExpressions);View on GitHub (pinned to dfa6dd587c)
Solutions
- Ensure the ForPath first argument is strictly a member-access chain like d => d.Address.City.
- Move any computation or method calls into the MapFrom callback inside the ForPath configuration action.
- If you need to map a computed value to a flat property, use ForMember with MapFrom instead of ForPath.
Example fix
// before — method call in ForPath path expression
CreateMap<Source, Dest>()
.ForPath(d => d.Address.GetFullName(), opt => opt.MapFrom(s => s.Name));
// after — pure member chain in ForPath, computation in MapFrom
CreateMap<Source, Dest>()
.ForPath(d => d.Address.FullName, opt => opt.MapFrom(s => s.FirstName + " " + s.LastName)); Defensive patterns
Strategy: validation
Validate before calling
// Validate the ForPath expression is a pure member chain before using it
Expression<Func<Dest, object>> pathExpr = d => d.Address.City;
bool isMemberPath = pathExpr.IsMemberPath(out _);
if (!isMemberPath)
throw new ArgumentException("ForPath requires a pure member-access chain (e.g., d => d.Prop.SubProp)."); Prevention
- Always use simple property/field access chains in ForPath (e.g., d => d.Address.City).
- Keep computation logic inside the MapFrom callback, not in the ForPath path expression.
- Write a quick unit test that builds the mapper to catch invalid ForPath expressions early.
When it happens
Trigger: Calling ForPath(d => d.Child.ComputeValue(), ...) where the expression contains a method call; or ForPath(d => d.Child + extra, ...) containing a binary operation; or any expression that isn't a straightforward d => d.Prop.SubProp chain.
Common situations: Confusing ForPath with MapFrom; trying to include computed logic in the destination path expression; passing a lambda that references external variables or invokes methods.
Related errors
- sourceExpression may not be null when mapping {DestinationMe
- Expression '{lambdaExpression}' must resolve to top-level me
- The type {typeMap.DestinationType.Name} does not have a cons
- Type '{conditionType.Name}' does not implement ICondition<TS
- Type '{conditionType.Name}' does not implement IPreCondition
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/e90c0b15702a7ea1.
Report an issue: GitHub.