{"record":{"id":"e90c0b15702a7ea1","repo":"LuckyPennySoftware/AutoMapper","slug":"only-member-accesses-are-allowed-destinationmemb","errorCode":null,"errorMessage":"Only member accesses are allowed. {destinationMember}","messagePattern":"Only member accesses are allowed\\. (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/AutoMapper/Configuration/MappingExpression.cs","lineNumber":63,"sourceCode":"    internal MemberConfigurationExpression ForMember(MemberInfo destinationProperty, Action<IMemberConfigurationExpression> memberOptions)\n    {\n        MemberConfigurationExpression expression = new(destinationProperty, SourceType);\n        MemberConfigurations.Add(expression);\n        memberOptions(expression);\n        return expression;\n    }\n}\npublic class MappingExpression<TSource, TDestination> : MappingExpressionBase<TSource, TDestination, IMappingExpression<TSource, TDestination>>,\n    IMappingExpression<TSource, TDestination>, IProjectionExpression<TSource, TDestination>\n{\n    public MappingExpression(MemberList memberList, bool projection) : base(memberList) => Projection = projection;\n    public MappingExpression(MemberList memberList, TypePair types) : base(memberList, types) { }\n    public IMappingExpression<TSource, TDestination> ForPath<TMember>(Expression<Func<TDestination, TMember>> destinationMember,\n        Action<IPathConfigurationExpression<TSource, TDestination, TMember>> memberOptions)\n    {\n        if (!destinationMember.IsMemberPath(out var chain))\n        {\n            throw new ArgumentOutOfRangeException(nameof(destinationMember), \"Only member accesses are allowed. \" + destinationMember);\n        }\n        PathConfigurationExpression<TSource, TDestination, TMember> expression = new(destinationMember, chain);\n        var firstMember = expression.MemberPath.First;\n        var firstMemberConfig = GetDestinationMemberConfiguration(firstMember);\n        if (firstMemberConfig == null)\n        {\n            IgnoreDestinationMember(firstMember, ignorePaths: false);\n        }\n        MemberConfigurations.Add(expression);\n        memberOptions(expression);\n        return this;\n    }\n    public IMappingExpression<TSource, TDestination> ForMember<TMember>(Expression<Func<TDestination, TMember>> destinationMember, Action<IMemberConfigurationExpression<TSource, TDestination, TMember>> memberOptions)\n    {\n        var memberInfo = ReflectionHelper.FindProperty(destinationMember);\n        return ForDestinationMember(memberInfo, memberOptions);\n    }\n    private void IncludeMembersCore(LambdaExpression[] memberExpressions) => TypeMapActions.Add(tm => tm.IncludedMembers = memberExpressions);","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/LuckyPennySoftware/AutoMapper/blob/dfa6dd587c5854b4beee5934beb39ba6e9569b84/src/AutoMapper/Configuration/MappingExpression.cs#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"Confusing ForPath with MapFrom; trying to include computed logic in the destination path expression; passing a lambda that references external variables or invokes methods.","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."],"exampleFix":"// before — method call in ForPath path expression\nCreateMap<Source, Dest>()\n    .ForPath(d => d.Address.GetFullName(), opt => opt.MapFrom(s => s.Name));\n\n// after — pure member chain in ForPath, computation in MapFrom\nCreateMap<Source, Dest>()\n    .ForPath(d => d.Address.FullName, opt => opt.MapFrom(s => s.FirstName + \" \" + s.LastName));","handlingStrategy":"validation","validationCode":"// Validate the ForPath expression is a pure member chain before using it\nExpression<Func<Dest, object>> pathExpr = d => d.Address.City;\nbool isMemberPath = pathExpr.IsMemberPath(out _);\nif (!isMemberPath)\n    throw new ArgumentException(\"ForPath requires a pure member-access chain (e.g., d => d.Prop.SubProp).\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["configuration","expression","forpath","mapping"],"backgroundTag":null,"analyzedSha":"dfa6dd587c5854b4beee5934beb39ba6e9569b84","analyzedAt":"2026-08-13T19:56:33.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}