LuckyPennySoftware/AutoMapper · error · AutoMapperMappingException
Error building queryable mapping strategy.
Error message
Error building queryable mapping strategy.
What it means
ProjectionBuilder translates a type map into a LINQ expression for ProjectTo (EF/IQueryable). For each destination property it calls TryProjectMember; any exception other than AutoMapperConfigurationException is wrapped in AutoMapperMappingException carrying the failing propertyMap and the original exception as InnerException. So the message names the surface, while InnerException is the real cause.
Source
Thrown at src/AutoMapper/QueryableExtensions/ProjectionBuilder.cs:131
{
foreach (var propertyMap in typeMap.PropertyMaps)
{
if (!propertyMap.CanResolveValue || !propertyMap.CanBeSet || typeMap.ConstructorParameterMatches(propertyMap.DestinationName))
{
continue;
}
try
{
var propertyProjection = TryProjectMember(propertyMap);
if (propertyProjection != null)
{
propertiesProjections.Add(Bind(propertyMap.DestinationMember, propertyProjection));
}
}
catch (Exception e) when (e is not AutoMapperConfigurationException)
{
throw new AutoMapperMappingException("Error building queryable mapping strategy.", e, propertyMap);
}
}
}
Expression TryProjectMember(MemberMap memberMap, Expression defaultSource = null)
{
MemberProjection memberProjection = new(memberMap);
letPropertyMaps.Push(memberProjection);
var memberExpression = ShouldExpand() ? ProjectMemberCore() : null;
letPropertyMaps.Pop();
return memberExpression;
bool ShouldExpand() => memberMap.ExplicitExpansion != true || request.ShouldExpand(letPropertyMaps.GetCurrentPath());
Expression ProjectMemberCore()
{
var memberTypeMap = _configuration.ResolveTypeMap(memberMap.SourceType, memberMap.DestinationType);
var resolvedSource = ResolveSource();
memberProjection.Expression ??= resolvedSource;
var memberRequest = request.InnerRequest(resolvedSource.Type, memberMap.DestinationType);
if (memberRequest.AlreadyExists && depth >= _configuration.RecursiveQueriesMaxDepth)View on GitHub (pinned to dfa6dd587c)
Solutions
- Read ex.InnerException plus the failing member (ex.Types / the propertyMap in the exception) to find which projection broke and why.
- Simplify the offending member's MapFrom to an expression the EF provider can translate, or remove server-side formatting.
- Project the raw column server-side and compute the derived value in-memory after ProjectTo returns.
- Ensure every nested type used in the projection has its own CreateMap/CreateProjection.
Example fix
// before CreateMap<Order, OrderDto>().ForCtorParam// or CreateMap<Order, OrderDto>().ForMember(d => d.Total, o => o.MapFrom(s => s.Lines.CalculateTotal())); // untranslatable method var dtos = ctx.Orders.ProjectTo<OrderDto>(_cfg).ToList(); // throws // after CreateMap<Order, OrderDto>().ForMember(d => d.Total, o => o.MapFrom(s => s.Lines.Sum(l => l.Price * l.Qty))); // translatable var dtos = ctx.Orders.ProjectTo<OrderDto>(_cfg).ToList();
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate at startup that projections build against the provider: configuration.AssertConfigurationIsValid(); // For runtime guards, keep a known-translatable expression set and a unit test // that runs ProjectTo against an in-memory IQueryable to confirm translation.
Try / catch
try
{
result = query.ProjectTo<Dest>(_cfg).ToList();
}
catch (AutoMapperMappingException ex) when (ex.Message.Contains("queryable mapping strategy"))
{
var root = ex.InnerException;
var failingMember = ex.MemberMap?.DestinationName;
// log root + failingMember, then simplify that member's MapFrom and retry
} Prevention
- Keep ProjectTo MapFrom lambdas free of custom methods; prefer arithmetic/string/linq the provider translates.
- Add an integration test that runs ProjectTo against the real provider, not just AssertConfigurationIsValid.
- When a value needs in-memory formatting, project the raw field and format after enumeration.
When it happens
Trigger: ProjectTo<Dest>(query) where a member's projection expression cannot be translated by the EF/LINQ provider: a MapFrom calling an unsupported method, a null reference inside the expression, a nested type with no map, or logic that is valid in-memory but not in the store.
Common situations: MapFrom lambdas invoking custom/static methods, .ToString() on providers that reject it, complex conditional logic, date/enum formatting, EF version/provider differences, or a missing CreateProjection for a referenced child type.
Related errors
AI-assisted analysis of LuckyPennySoftware/AutoMapper@dfa6dd587c (2026-08-13).
Data as JSON: /api/errors/2ddececa73d49aef.
Report an issue: GitHub.