dotnet/efcore · error · NotSupportedException
Parameter clash during expression lifting for: {parameter.Na
Error message
Parameter clash during expression lifting for: {parameter.Name} What it means
Thrown in VisitBlock (expression context) when _liftedState.Variables.TryAdd(parameter, uniquifiedName) fails - the same ParameterExpression instance is already registered in the lifted variables for the current lift scope. NotSupportedException. Part of EF Core's LINQ-to-C# syntax translation.
Source
Thrown at src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs:507
var stackFrame = _stack.Peek();
// Do a 1st pass to identify and register any labels, since goto can appear before its label.
PreprocessLabels();
// Go over the block's variables, assign names to any unnamed ones and uniquify. Then add them to our stack frame, unless
// this is an expression block that will get lifted.
foreach (var parameter in block.Variables)
{
var (variables, variableNames) = (stackFrame.Variables, stackFrame.VariableNames);
var uniquifiedName = UniquifyVariableName(parameter.Name ?? "unnamed");
if (blockContext == ExpressionContext.Expression)
{
if (!_liftedState.Variables.TryAdd(parameter, uniquifiedName))
{
throw new NotSupportedException("Parameter clash during expression lifting for: " + parameter.Name);
}
_liftedState.VariableNames.Add(uniquifiedName);
}
else
{
if (!variables.TryAdd(parameter, uniquifiedName))
{
throw new InvalidOperationException(
DesignStrings.SameParameterExpressionDeclaredAsVariableInNestedBlocks(parameter.Name ?? "<null>"));
}
variableNames.Add(uniquifiedName);
}
}
var unassignedVariables = block.Variables.ToList();
View on GitHub (pinned to dbf9771522)
Solutions
- Use distinct ParameterExpression instances for each variable scope being lifted.
- Rebuild the expression tree with fresh parameters instead of reusing one.
Example fix
// before var p = Expression.Parameter(typeof(int), "x"); // same 'p' reused in two lifted blocks // after var p1 = Expression.Parameter(typeof(int), "x"); var p2 = Expression.Parameter(typeof(int), "x");
Defensive patterns
Strategy: validation
Validate before calling
// Ensure ParameterExpression instances are unique within a lifted scope
var seen = new HashSet<ParameterExpression>();
foreach (var block in AllBlocks(expr))
foreach (var v in block.Variables)
if (!seen.Add(v))
throw new InvalidOperationException(
$"ParameterExpression '{v.Name}' is reused across lifted blocks; create distinct instances."); Prevention
- Never reuse the same ParameterExpression instance across sibling blocks that may be lifted together.
- Generate fresh ParameterExpression objects per scope when building trees programmatically.
When it happens
Trigger: An expression block being lifted that declares a parameter already present in the lifted state (same ParameterExpression instance reused across lifted blocks).
Common situations: Programmatically reusing the same ParameterExpression instance across blocks that get lifted together; expression-tree construction bugs sharing a parameter variable.
Related errors
- Lifted expressions remaining at top-level in expression cont
- The same ParameterExpression instance with name '{parameter}
- Label on last expression of an expression block
- TranslateCatchBlock: unnamed parameter as catch variable
- Trying to evaluate a non-expression condition in expression
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/43757c750b11d5c4.
Report an issue: GitHub.