{"record":{"id":"43757c750b11d5c4","repo":"dotnet/efcore","slug":"parameter-clash-during-expression-lifting-for-pa","errorCode":null,"errorMessage":"Parameter clash during expression lifting for: {parameter.Name}","messagePattern":"Parameter clash during expression lifting for: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":507,"sourceCode":"\n        var stackFrame = _stack.Peek();\n\n        // Do a 1st pass to identify and register any labels, since goto can appear before its label.\n        PreprocessLabels();\n\n        // Go over the block's variables, assign names to any unnamed ones and uniquify. Then add them to our stack frame, unless\n        // this is an expression block that will get lifted.\n        foreach (var parameter in block.Variables)\n        {\n            var (variables, variableNames) = (stackFrame.Variables, stackFrame.VariableNames);\n\n            var uniquifiedName = UniquifyVariableName(parameter.Name ?? \"unnamed\");\n\n            if (blockContext == ExpressionContext.Expression)\n            {\n                if (!_liftedState.Variables.TryAdd(parameter, uniquifiedName))\n                {\n                    throw new NotSupportedException(\"Parameter clash during expression lifting for: \" + parameter.Name);\n                }\n\n                _liftedState.VariableNames.Add(uniquifiedName);\n            }\n            else\n            {\n                if (!variables.TryAdd(parameter, uniquifiedName))\n                {\n                    throw new InvalidOperationException(\n                        DesignStrings.SameParameterExpressionDeclaredAsVariableInNestedBlocks(parameter.Name ?? \"<null>\"));\n                }\n\n                variableNames.Add(uniquifiedName);\n            }\n        }\n\n        var unassignedVariables = block.Variables.ToList();\n","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L489-L525","documentation":"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.","triggerScenarios":"An expression block being lifted that declares a parameter already present in the lifted state (same ParameterExpression instance reused across lifted blocks).","commonSituations":"Programmatically reusing the same ParameterExpression instance across blocks that get lifted together; expression-tree construction bugs sharing a parameter variable.","solutions":["Use distinct ParameterExpression instances for each variable scope being lifted.","Rebuild the expression tree with fresh parameters instead of reusing one."],"exampleFix":"// before\nvar p = Expression.Parameter(typeof(int), \"x\");\n// same 'p' reused in two lifted blocks\n// after\nvar p1 = Expression.Parameter(typeof(int), \"x\");\nvar p2 = Expression.Parameter(typeof(int), \"x\");","handlingStrategy":"validation","validationCode":"// Ensure ParameterExpression instances are unique within a lifted scope\nvar seen = new HashSet<ParameterExpression>();\nforeach (var block in AllBlocks(expr))\n    foreach (var v in block.Variables)\n        if (!seen.Add(v))\n            throw new InvalidOperationException(\n                $\"ParameterExpression '{v.Name}' is reused across lifted blocks; create distinct instances.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never reuse the same ParameterExpression instance across sibling blocks that may be lifted together.","Generate fresh ParameterExpression objects per scope when building trees programmatically."],"tags":["efcore","expression-trees","parameterexpression","lifting"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}