LuckyPennySoftware/AutoMapper · error · AutoMapperConfigurationException

The type {typeMap.DestinationType.Name} does not have a cons

Error message

The type {typeMap.DestinationType.Name} does not have a constructor.\n{typeMap.DestinationType.FullName}

What it means

Thrown when ForCtorParam is configured for a destination type whose ConstructorMap is null, meaning AutoMapper found no constructor it can use for constructor mapping. This occurs when the destination type has no accessible parameterized constructor that AutoMapper can match against source members, or when constructor mapping was bypassed. The Configure method checks typeMap.ConstructorMap and throws before attempting to resolve the parameter.

Source

Thrown at src/AutoMapper/Configuration/CtorParamConfigurationExpression.cs:61

    public void MapFrom<TMember>(Expression<Func<TSource, TMember>> sourceMember) =>
        _ctorParamActions.Add(cpm => cpm.MapFrom(sourceMember));
    public void MapFrom<TMember>(Func<TSource, ResolutionContext, TMember> resolver)
    {
        Expression<Func<TSource, TDestination, TMember, ResolutionContext, TMember>> resolverExpression = (src, dest, destMember, ctxt) => resolver(src, ctxt);
        _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

  1. Ensure the destination type has at least one public constructor with parameters AutoMapper can resolve.
  2. Remove the ForCtorParam call if you are already using ConstructUsing to create the destination instance.
  3. If the destination is an interface, map to a concrete implementation type or use AsProxy.
  4. Make the constructor public if it was private/internal.

Example fix

// before — no public constructor on Dest
public class Dest { private Dest() { } }
CreateMap<Source, Dest>().ForCtorParam("name", opt => opt.MapFrom("Name"));

// after — add a public constructor
public class Dest { public Dest(string name) { Name = name; } public string Name { get; set; } }
Defensive patterns

Strategy: validation

Validate before calling

// Check the destination type has a public constructor before using ForCtorParam
var ctors = typeof(TDestination).GetConstructors(BindingFlags.Public | BindingFlags.Instance);
if (ctors.Length == 0)
    throw new InvalidOperationException($"{typeof(TDestination).Name} has no public constructor; cannot use ForCtorParam.");
// Safe to call ForCtorParam now

Prevention

When it happens

Trigger: Calling .ForCtorParam("id", opt => ...) on a CreateMap whose destination type has no public constructor (only a parameterless one, or none), or whose destination is an interface or abstract class. Also happens when ConstructUsing overrides the constructor so ConstructorMap is never populated.

Common situations: Destination type is an interface or abstract class with no concrete constructor; destination type only has a private or internal constructor; you used ConstructUsing to supply a custom factory and also tried ForCtorParam.

Related errors


AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13). Data as JSON: /api/errors/cd70ac6b7c63de31. Report an issue: GitHub.