{"record":{"id":"0aa98e1bd10f0949","repo":"dotnet/efcore","slug":"binaryexpression-with-binary-nodetype","errorCode":null,"errorMessage":"BinaryExpression with {binary.NodeType}","messagePattern":"BinaryExpression with (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":412,"sourceCode":"            ExpressionType.LessThanOrEqual => SyntaxKind.LessThanOrEqualExpression,\n\n            ExpressionType.AndAlso => SyntaxKind.LogicalAndExpression,\n            ExpressionType.OrElse => SyntaxKind.LogicalOrExpression,\n            ExpressionType.AndAssign => SyntaxKind.AndAssignmentExpression,\n            ExpressionType.OrAssign => SyntaxKind.OrAssignmentExpression,\n\n            ExpressionType.And => SyntaxKind.BitwiseAndExpression,\n            ExpressionType.Or => SyntaxKind.BitwiseOrExpression,\n            ExpressionType.ExclusiveOr => SyntaxKind.ExclusiveOrExpression,\n            ExpressionType.LeftShift => SyntaxKind.LeftShiftExpression,\n            ExpressionType.RightShift => SyntaxKind.RightShiftExpression,\n            // TODO UnsignedRightShiftExpression\n\n            ExpressionType.TypeIs => SyntaxKind.IsExpression,\n            ExpressionType.TypeAs => SyntaxKind.AsExpression,\n            ExpressionType.Coalesce => SyntaxKind.CoalesceExpression,\n\n            _ => throw new ArgumentOutOfRangeException(\"BinaryExpression with \" + binary.NodeType)\n        };\n\n        Result = BinaryExpression(syntaxKind, left, right);\n\n        return binary;\n\n        Expression VisitAssignment(BinaryExpression assignment, SyntaxKind kind)\n        {\n            // Detect assignment where the lvalue is a private field or a property with a private accessor; these are handled via\n            // [UnsafeAccessor].\n            if (assignment.Left is MemberExpression\n                {\n                    Member: FieldInfo { IsPublic: false } or PropertyInfo { SetMethod.IsPublic: false }\n                } memberExpression)\n            {\n                TranslateNonPublicMemberAssignment(memberExpression, assignment.Right, kind);\n\n                return assignment;","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L394-L430","documentation":"Thrown by LinqToCSharpSyntaxTranslator.VisitBinary when the BinaryExpression.NodeType does not match any of the supported ExpressionType cases in the syntax-kind switch (which covers arithmetic, comparison, logical, shift, is/as, coalesce, and assignment operators). Any binary node type outside that set hits the ArgumentOutOfRange fallback.","triggerScenarios":"An expression tree contains a binary node type that the translator has not been taught to render, e.g. ExpressionType.Assign handled elsewhere but a future/new ExpressionType, a user-defined binary operator represented as an exotic NodeType, or an extension node masquerading as a binary.","commonSituations":"Upgrading to a newer .NET runtime that introduced additional ExpressionType values; third-party expression-tree builders producing non-standard node types; building expression trees by hand with mismatched NodeType vs. operand kinds.","solutions":["Inspect binary.NodeType in a debugger to identify the unsupported value and rewrite the tree to use a supported equivalent (e.g. express the operation as a method call).","Replace the exotic binary with an equivalent Expression.Call to a method the translator supports.","If this is a newly-introduced standard ExpressionType, file/track an EF Core issue to extend the switch; in the meantime avoid that operator in trees destined for code generation."],"exampleFix":"// before — exotic NodeType reaching VisitBinary\n// (e.g. hand-built BinaryExpression with an unsupported NodeType)\nvar weird = Expression.MakeBinary(\n    someCustomNodeType, left, right);\n\n// after — express the same operation as a supported method call\nvar equivalent = Expression.Call(\n    typeof(MyOps), nameof(MyOps.DoOp), null, left, right);","handlingStrategy":"validation","validationCode":"// Pre-walk the tree to confirm all binary node types are supported.\nusing System.Linq.Expressions;\n\nstatic readonly HashSet<ExpressionType> SupportedBinaryTypes = new()\n{\n    ExpressionType.Equal, ExpressionType.NotEqual,\n    ExpressionType.Add, ExpressionType.AddChecked,\n    ExpressionType.Subtract, ExpressionType.SubtractChecked,\n    ExpressionType.Multiply, ExpressionType.MultiplyChecked,\n    ExpressionType.Divide, ExpressionType.Modulo,\n    ExpressionType.GreaterThan, ExpressionType.GreaterThanOrEqual,\n    ExpressionType.LessThan, ExpressionType.LessThanOrEqual,\n    ExpressionType.AndAlso, ExpressionType.OrElse,\n    ExpressionType.AndAssign, ExpressionType.OrAssign,\n    ExpressionType.And, ExpressionType.Or,\n    ExpressionType.ExclusiveOr, ExpressionType.LeftShift, ExpressionType.RightShift,\n    ExpressionType.TypeIs, ExpressionType.TypeAs, ExpressionType.Coalesce,\n};\n\nbool AllBinarySupported(Expression e)\n{\n    bool ok = true;\n    new BinaryChecker(b => { if (!SupportedBinaryTypes.Contains(b.NodeType)) ok = false; }).Visit(e);\n    return ok;\n}\n\nclass BinaryChecker(Action<BinaryExpression> onBinary) : ExpressionVisitor\n{\n    protected override Expression VisitBinary(BinaryExpression b) { onBinary(b); return base.VisitBinary(b); }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-validate expression trees against the supported NodeType set before translation.","Express non-standard operations as method calls rather than exotic binary node types.","When upgrading the runtime, re-check the supported set in case new ExpressionType values appear."],"tags":["ef-core","expression-trees","linq-expressions","code-generation","binary-expressions"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}