{"record":{"id":"961c6ebccadc1118","repo":"LuckyPennySoftware/AutoMapper","slug":"typemap-destinationtype-name-does-not-have-a-mat","errorCode":null,"errorMessage":"{typeMap.DestinationType.Name} does not have a matching constructor with a parameter named '{CtorParamName}'.\\n{typeMap.DestinationType.FullName}.{typeMap.CheckRecord()}","messagePattern":"(.+?) does not have a matching constructor with a parameter named '(.+?)'\\.\\\\n(.+?)\\.(.+?)","errorType":"validation","errorClass":"AutoMapperConfigurationException","httpStatus":null,"severity":"error","filePath":"src/AutoMapper/Configuration/CtorParamConfigurationExpression.cs","lineNumber":66,"sourceCode":"        _ctorParamActions.Add(cpm => cpm.SetResolver(new FuncResolver(resolverExpression)));\n    }\n    public void MapFrom(string sourceMembersPath)\n    {\n        var sourceMembers = ReflectionHelper.GetMemberPath(SourceType, sourceMembersPath);\n        _ctorParamActions.Add(cpm => cpm.MapFrom(sourceMembersPath, sourceMembers));\n    }\n    public void ExplicitExpansion(bool value) => _ctorParamActions.Add(cpm => cpm.ExplicitExpansion = value);\n    public void Configure(TypeMap typeMap)\n    {\n        var ctorMap = typeMap.ConstructorMap;\n        if (ctorMap == null)\n        {\n            throw new AutoMapperConfigurationException($\"The type {typeMap.DestinationType.Name} does not have a constructor.\\n{typeMap.DestinationType.FullName}\");\n        }\n        var parameter = ctorMap[CtorParamName];\n        if (parameter == null)\n        {\n            throw new AutoMapperConfigurationException($\"{typeMap.DestinationType.Name} does not have a matching constructor with a parameter named '{CtorParamName}'.\\n{typeMap.DestinationType.FullName}.{typeMap.CheckRecord()}\");\n        }\n        foreach (var action in _ctorParamActions)\n        {\n            action(parameter);\n        }\n    }\n}","sourceCodeStart":48,"sourceCodeEnd":73,"githubUrl":"https://github.com/LuckyPennySoftware/AutoMapper/blob/dfa6dd587c5854b4beee5934beb39ba6e9569b84/src/AutoMapper/Configuration/CtorParamConfigurationExpression.cs#L48-L73","documentation":"Thrown when ForCtorParam(\"paramName\", ...) is configured but the destination constructor selected by AutoMapper has no parameter with that exact name. The indexer ctorMap[CtorParamName] returns null. The message appends CheckRecord() which adds a hint about public constructors when the destination is a C# record with a compiler-generated protected constructor.","triggerScenarios":"Calling .ForCtorParam(\"Id\", ...) when the constructor parameter is actually named \"id\" (case mismatch); renaming a constructor parameter without updating the mapping; mapping to a record where the primary constructor parameter name differs from the ForCtorParam argument.","commonSituations":"Parameter renamed during refactoring; case-sensitivity mismatch (C# is case-sensitive); record types where AutoMapper selected a different overload; multiple constructors and AutoMapper picked a different one than expected.","solutions":["Verify the exact constructor parameter name by inspecting the destination type's constructor signature — names are case-sensitive.","For C# records, ensure the ForCtorParam name matches the primary constructor parameter exactly.","If AutoMapper selected the wrong constructor overload, use ConstructUsing to control which constructor is invoked.","When mapping to records, prefer public constructors as the CheckRecord hint suggests."],"exampleFix":"// before — parameter name mismatch\npublic record Dest(int Identifier);\nCreateMap<Source, Dest>().ForCtorParam(\"Id\", opt => opt.MapFrom(s => s.Id));\n\n// after — match the actual parameter name\nCreateMap<Source, Dest>().ForCtorParam(\"Identifier\", opt => opt.MapFrom(s => s.Id));","handlingStrategy":"validation","validationCode":"// Verify the constructor parameter name exists before configuring ForCtorParam\nvar paramName = \"Identifier\";\nvar ctor = typeof(TDestination).GetConstructors().FirstOrDefault(c => c.GetParameters().Any(p => p.Name == paramName));\nif (ctor == null)\n    throw new InvalidOperationException($\"No constructor parameter named '{paramName}' on {typeof(TDestination).Name}. \" +\n        $\"Available: {string.Join(\", \", typeof(TDestination).GetConstructors().SelectMany(c => c.GetParameters().Select(p => p.Name)))}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always cross-check ForCtorParam names against the actual constructor signature.","For C# records, use the primary constructor parameter names exactly.","Add a unit test that builds the mapper to catch name mismatches at test time.","Consider using ConstructUsing for complex constructor scenarios to avoid fragile name-based matching."],"tags":["configuration","constructor","ctor-param","records"],"backgroundTag":null,"analyzedSha":"dfa6dd587c5854b4beee5934beb39ba6e9569b84","analyzedAt":"2026-08-13T19:56:33.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}