{"record":{"id":"71096b7278a819c4","repo":"LuckyPennySoftware/AutoMapper","slug":"error-building-member-mapping-strategy","errorCode":null,"errorMessage":"Error building member mapping strategy.","messagePattern":"Error building member mapping strategy\\.","errorType":"exception","errorClass":"AutoMapperMappingException","httpStatus":null,"severity":"error","filePath":"src/AutoMapper/Execution/TypeMapPlanBuilder.cs","lineNumber":314,"sourceCode":"            if (!propertyMap.CanResolveValue)\n            {\n                continue;\n            }\n\n            try\n            {\n                var property = TryMemberMap(propertyMap,\n                    CreatePropertyMapFunc(propertyMap, _destination, propertyMap.DestinationMember));\n                if (_typeMap.ConstructorParameterMatches(propertyMap.DestinationName))\n                {\n                    property = _initialDestination.IfNullElse(_configuration.Default(property.Type), property);\n                }\n\n                actions.Add(property);\n            }\n            catch (Exception e) when (e is not AutoMapperConfigurationException)\n            {\n                throw new AutoMapperMappingException(\"Error building member mapping strategy.\", e, propertyMap);\n            }\n        }\n    }\n\n    private Expression TryPathMap(PathMap pathMap)\n    {\n        var destination =\n            ((MemberExpression)_configuration.ConvertReplaceParameters(pathMap.DestinationExpression, _destination))\n            .Expression;\n        var pathMapFunc = CreatePropertyMapFunc(pathMap, destination, pathMap.MemberPath.Last);\n        _expressions.Clear();\n        foreach (var member in destination.GetMemberExpressions())\n        {\n            var setter = GetSetter(member);\n            var ifNull = setter == null\n                ? Throw(Constant(new NullReferenceException($\"{member} cannot be null because it's used by ForPath.\")),\n                    member.Type)\n                : (Expression)Assign(setter, ObjectFactory.GenerateConstructorExpression(member.Type, _configuration));","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/LuckyPennySoftware/AutoMapper/blob/dfa6dd587c5854b4beee5934beb39ba6e9569b84/src/AutoMapper/Execution/TypeMapPlanBuilder.cs#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — incompatible member types, no converter\nCreateMap<Source, Dest>()\n    .ForMember(d => d.Amount, opt => opt.MapFrom(s => s.AmountString));\n// Amount is decimal, AmountString is string\n\n// after — add explicit conversion in MapFrom\nCreateMap<Source, Dest>()\n    .ForMember(d => d.Amount, opt => opt.MapFrom(s => decimal.Parse(s.AmountString)));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Dest>()\n        .ForMember(d => d.Amount, opt => opt.MapFrom(s => s.AmountValue)));\n    config.CompileMaps();\n}\ncatch (AutoMapperMappingException ex) when (ex.Message.Contains(\"member mapping strategy\"))\n{\n    // ex.InnerException has the real error; ex.MemberMap identifies the failing property\n    logger.LogError(ex.InnerException, \"Member plan build failed for {Member}\", ex.MemberMap?.DestinationMember);\n}","preventionTips":["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."],"tags":["execution","formember","expression-tree","plan-building"],"backgroundTag":null,"analyzedSha":"dfa6dd587c5854b4beee5934beb39ba6e9569b84","analyzedAt":"2026-08-13T19:56:33.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}