LuckyPennySoftware/AutoMapper · error · AutoMapperConfigurationException
{typeMap.DestinationType.Name} does not have a matching cons
Error message
{typeMap.DestinationType.Name} does not have a matching constructor with a parameter named '{CtorParamName}'.\n{typeMap.DestinationType.FullName}.{typeMap.CheckRecord()} What it means
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.
Source
Thrown at src/AutoMapper/Configuration/CtorParamConfigurationExpression.cs:66
_ctorParamActions.Add(cpm => cpm.SetResolver(new FuncResolver(resolverExpression)));
}
public void MapFrom(string sourceMembersPath)
{
var sourceMembers = ReflectionHelper.GetMemberPath(SourceType, sourceMembersPath);
_ctorParamActions.Add(cpm => cpm.MapFrom(sourceMembersPath, sourceMembers));
}
public void ExplicitExpansion(bool value) => _ctorParamActions.Add(cpm => cpm.ExplicitExpansion = value);
public void Configure(TypeMap typeMap)
{
var ctorMap = typeMap.ConstructorMap;
if (ctorMap == null)
{
throw new AutoMapperConfigurationException($"The type {typeMap.DestinationType.Name} does not have a constructor.\n{typeMap.DestinationType.FullName}");
}
var parameter = ctorMap[CtorParamName];
if (parameter == null)
{
throw new AutoMapperConfigurationException($"{typeMap.DestinationType.Name} does not have a matching constructor with a parameter named '{CtorParamName}'.\n{typeMap.DestinationType.FullName}.{typeMap.CheckRecord()}");
}
foreach (var action in _ctorParamActions)
{
action(parameter);
}
}
}View on GitHub (pinned to dfa6dd587c)
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.
Example fix
// before — parameter name mismatch
public record Dest(int Identifier);
CreateMap<Source, Dest>().ForCtorParam("Id", opt => opt.MapFrom(s => s.Id));
// after — match the actual parameter name
CreateMap<Source, Dest>().ForCtorParam("Identifier", opt => opt.MapFrom(s => s.Id)); Defensive patterns
Strategy: validation
Validate before calling
// Verify the constructor parameter name exists before configuring ForCtorParam
var paramName = "Identifier";
var ctor = typeof(TDestination).GetConstructors().FirstOrDefault(c => c.GetParameters().Any(p => p.Name == paramName));
if (ctor == null)
throw new InvalidOperationException($"No constructor parameter named '{paramName}' on {typeof(TDestination).Name}. " +
$"Available: {string.Join(", ", typeof(TDestination).GetConstructors().SelectMany(c => c.GetParameters().Select(p => p.Name)))}"); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The type {typeMap.DestinationType.Name} does not have a cons
- Type '{objectConstructorType.Name}' does not implement IDest
- Duplicate CreateMap calls: {error.Types.SourceType.FullName}
- Cannot find any profiles with the name '{profileName}'.
- Only member accesses are allowed. {destinationMember}
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/961c6ebccadc1118.
Report an issue: GitHub.