dotnet/efcore · error · NotSupportedException
Lambda with modifiers not supported: {lambda.Modifiers}
Error message
Lambda with modifiers not supported: {lambda.Modifiers} What it means
Thrown by VisitLambdaExpression when lambda.Modifiers.Any() is true. The translator rejects any lambda modifier (e.g. the C# 9 'static' modifier on static lambdas) because it only models plain delegates in LINQ expression trees. Part of EF Core's precompiled-query C#-to-LINQ translation.
Source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:1037
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression DefaultVisit(SyntaxNode node)
=> throw new NotSupportedException($"Unsupported syntax node of type '{node.GetType()}': {node}");
private Expression VisitLambdaExpression(AnonymousFunctionExpressionSyntax lambda, Type? expectedType = null)
{
if (lambda.ExpressionBody is null)
{
throw new NotSupportedException("Lambda with null expression body");
}
if (lambda.Modifiers.Any())
{
throw new NotSupportedException("Lambda with modifiers not supported: " + lambda.Modifiers);
}
if (!lambda.AsyncKeyword.IsKind(SyntaxKind.None))
{
throw new NotSupportedException("Async lambdas are not supported");
}
var lambdaParameters = lambda switch
{
SimpleLambdaExpressionSyntax simpleLambda => SyntaxFactory.SingletonSeparatedList(simpleLambda.Parameter),
ParenthesizedLambdaExpressionSyntax parenthesizedLambda => parenthesizedLambda.ParameterList.Parameters,
_ => throw new UnreachableException()
};
var translatedParameters = new List<ParameterExpression>();
foreach (var parameter in lambdaParameters)
{View on GitHub (pinned to dbf9771522)
Solutions
- Remove the modifier (e.g. drop 'static') from the lambda.
- If the lambda must not capture, move it to a static helper method and reference that method directly.
Example fix
// before .Select(static x => x.Id) // after .Select(x => x.Id)
Defensive patterns
Strategy: validation
Validate before calling
foreach (var lambda in root.DescendantNodes().OfType<AnonymousFunctionExpressionSyntax>())
{
if (lambda.Modifiers.Any())
throw new InvalidOperationException(
$"Lambda with modifiers ({string.Join(", ", lambda.Modifiers)}) at {lambda.GetLocation()} is not supported.");
} Prevention
- Avoid static lambdas and other modifiers in query code that will be precompiled.
- Document the subset of C# lambda syntax supported by precompiled queries for your team.
When it happens
Trigger: Translating C# source containing a static lambda (static () => ...) or any other lambda modifier during precompiled query processing.
Common situations: Using C# 9+ static anonymous functions/lambdas inside query code that gets precompiled; source generators encountering modern C# lambda modifier syntax.
Related errors
- Lambda with null expression body
- Async lambdas are not supported
- Lifted expressions remaining at top-level in expression cont
- ArrayCreation: non-array type symbol: {implicitArrayCreation
- ArrayCreation: multi-dimensional array: {implicitArrayCreati
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/a209dc52e6c17f2a.
Report an issue: GitHub.