{"record":{"id":"5552f894ea0878ee","repo":"dotnet/efcore","slug":"multiple-labels-on-the-same-statement","errorCode":null,"errorMessage":"Multiple labels on the same statement","messagePattern":"Multiple labels on the same statement","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":552,"sourceCode":"            _onLastLambdaLine = parentOnLastLambdaLine && onLastBlockLine;\n\n            // Any lines before the last are evaluated in statement context (they aren't returned); the last line is evaluated in the\n            // context of the block as a whole. _context now refers to the statement's context, blockContext to the block's.\n            var statementContext = onLastBlockLine ? _context : ExpressionContext.Statement;\n\n            SyntaxNode translated;\n            using (ChangeContext(statementContext))\n            {\n                translated = Translate(expression);\n            }\n\n            // If we have a labeled statement, unwrap it and keep the label as pending. VisitLabel returns a dummy statement (since\n            // LINQ labels don't have a statement, unlike C#), so we'll skip that statement and add the label to the next real one.\n            if (translated is LabeledStatementSyntax labeledStatement)\n            {\n                if (pendingLabeledStatement is not null)\n                {\n                    throw new NotImplementedException(\"Multiple labels on the same statement\");\n                }\n\n                pendingLabeledStatement = labeledStatement;\n                translated = labeledStatement.Statement;\n            }\n\n            // Syntax optimization. This is an assignment of a block variable to some value. Render this as:\n            // var x = <expression>;\n            // ... instead of:\n            // int x;\n            // x = <expression>;\n            // ... except for expression context (i.e. on the last line), where we just return the value if needed.\n            if (expression is BinaryExpression { NodeType: ExpressionType.Assign, Left: ParameterExpression lValue }\n                && translated is AssignmentExpressionSyntax { Right: var valueSyntax }\n                && statementContext == ExpressionContext.Statement\n                && unassignedVariables.Remove(lValue))\n            {\n                var useExplicitVariableType = valueSyntax.Kind() == SyntaxKind.NullLiteralExpression;","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L534-L570","documentation":"Thrown in VisitBlock when a second LabeledStatementSyntax is encountered while one is already pending (pendingLabeledStatement is not null). Two labels target the same statement, which the translator does not support. NotImplementedException. Part of EF Core's LINQ-to-C# syntax translation.","triggerScenarios":"An expression block where two label targets land such that both get attached to the same statement.","commonSituations":"Expression trees with multiple goto labels landing on consecutive positions; uncommon control-flow patterns in generated expression trees.","solutions":["Separate the labels so each lands on its own statement (insert a no-op statement between them).","Restructure the control flow to avoid co-located labels."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid expression-tree control flow where multiple labels land on the same statement.","Insert a no-op (EmptyStatement) between co-located labels if this pattern is unavoidable."],"tags":["efcore","expression-trees","labels","goto","control-flow"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}