{"record":{"id":"62931f6be6a444a3","repo":"dotnet/efcore","slug":"binaryexpressionsyntax-with-binary-kind","errorCode":null,"errorMessage":"BinaryExpressionSyntax with {binary.Kind()}","messagePattern":"BinaryExpressionSyntax with (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":324,"sourceCode":"            SyntaxKind.EqualsExpression => Equal(left, right),\n            SyntaxKind.NotEqualsExpression => NotEqual(left, right),\n            SyntaxKind.LessThanExpression => LessThan(left, right),\n            SyntaxKind.LessThanOrEqualExpression => LessThanOrEqual(left, right),\n            SyntaxKind.GreaterThanExpression => GreaterThan(left, right),\n            SyntaxKind.GreaterThanOrEqualExpression => GreaterThanOrEqual(left, right),\n            SyntaxKind.IsExpression => TypeIs(\n                left, right is ConstantExpression { Value: Type type }\n                    ? type\n                    : throw new InvalidOperationException(\n                        $\"Encountered {SyntaxKind.IsExpression} with non-constant type right argument: {right}\")),\n            SyntaxKind.AsExpression => TypeAs(\n                left, right is ConstantExpression { Value: Type type }\n                    ? type\n                    : throw new InvalidOperationException(\n                        $\"Encountered {SyntaxKind.AsExpression} with non-constant type right argument: {right}\")),\n            SyntaxKind.CoalesceExpression => Coalesce(left, right),\n\n            _ => throw new ArgumentOutOfRangeException($\"BinaryExpressionSyntax with {binary.Kind()}\")\n        };\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitCastExpression(CastExpressionSyntax cast)\n        => Convert(Visit(cast.Expression), ResolveType(cast.Type));\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L306-L342","documentation":"`VisitBinaryExpression`'s switch handles a fixed set of binary kinds (arithmetic, logical, bitwise, comparison, `is`/`as`/`??`); the `default` arm throws `ArgumentOutOfRangeException` for any other `binary.Kind()`. Newer C# binary operators (e.g. coalesce-assignment `??=`, `>>>`) fall through here.","triggerScenarios":"A precompiled query containing a binary expression whose `SyntaxKind` is not in the translator's switch — e.g. `SyntaxKind.CoalesceAssignmentExpression` or compound assignments that the visitor still sees as binary.","commonSituations":"Using newer C# compound-assignment operators inside a query lambda, or syntax trees synthesized with uncommon binary kinds.","solutions":["Rewrite the operator into a supported form (e.g. `a ??= b` → `a = a ?? b` applied outside the query).","Avoid compound/coalesce-assignment operators inside precompiled query expressions.","Hoist the computation out of the query."],"exampleFix":"// before\nvar q = ctx.Items.Where(i => (i.Tag ??= \"default\") == \"default\");\n// after\nvar q = ctx.Items.Where(i => (i.Tag ?? \"default\") == \"default\");","handlingStrategy":"validation","validationCode":"// Block binary kinds the translator does not support.\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.CSharp;\nvar supported = new HashSet<SyntaxKind>(new[]\n{\n    SyntaxKind.AddExpression, SyntaxKind.SubtractExpression, SyntaxKind.MultiplyExpression,\n    SyntaxKind.DivideExpression, SyntaxKind.ModuloExpression, SyntaxKind.LeftShiftExpression,\n    SyntaxKind.RightShiftExpression, SyntaxKind.LogicalOrExpression, SyntaxKind.LogicalAndExpression,\n    SyntaxKind.BitwiseOrExpression, SyntaxKind.BitwiseAndExpression, SyntaxKind.ExclusiveOrExpression,\n    SyntaxKind.EqualsExpression, SyntaxKind.NotEqualsExpression, SyntaxKind.LessThanExpression,\n    SyntaxKind.LessThanOrEqualExpression, SyntaxKind.GreaterThanExpression,\n    SyntaxKind.GreaterThanOrEqualExpression, SyntaxKind.IsExpression, SyntaxKind.AsExpression,\n    SyntaxKind.CoalesceExpression\n});\nvar bad = node.DescendantNodes().OfType<BinaryExpressionSyntax>()\n    .FirstOrDefault(b => !supported.Contains(b.Kind()));\nif (bad is not null)\n    throw new NotSupportedException($\"Binary operator {bad.Kind()} is not supported in precompiled queries.\");\n\ntranslator.Translate(node, semanticModel);","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"BinaryExpressionSyntax with\"))\n{ /* rewrite the unsupported operator (e.g. ??= -> ??) and retry */ }","preventionTips":["Avoid compound/coalesce-assignment operators inside precompiled queries.","Stick to standard arithmetic, logical, bitwise, comparison, `is`/`as`/`??` operators.","Hoist non-translatable computations out of the query."],"tags":["ef-core","precompiled-queries","expression-trees","unsupported-construct","binary-operators"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}