{"record":{"id":"7b6448c6fc294ecf","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-left","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'left')","messagePattern":"Value cannot be null\\. \\(Parameter 'left'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Structures/Query.cs","lineNumber":195,"sourceCode":"        /// <summary>\n        /// Returns all documents that has value in values list (IN)\n        /// </summary>\n        public static BsonExpression In(string field, IEnumerable<BsonValue> values)\n        {\n            return In(field, new BsonArray(values));\n        }\n\n        /// <summary>\n        /// Get all operands to works with array or enumerable values\n        /// </summary>\n        public static QueryAny Any() => new QueryAny();\n\n        /// <summary>\n        /// Returns document that exists in BOTH queries results. If both queries has indexes, left query has index preference (other side will be run in full scan)\n        /// </summary>\n        public static BsonExpression And(BsonExpression left, BsonExpression right)\n        {\n            if (left == null) throw new ArgumentNullException(nameof(left));\n            if (right == null) throw new ArgumentNullException(nameof(right));\n\n            return $\"({left.Source} AND {right.Source})\";\n        }\n\n        /// <summary>\n        /// Returns document that exists in ALL queries results.\n        /// </summary>\n        public static BsonExpression And(params BsonExpression[] queries)\n        {\n            if (queries == null || queries.Length < 2) throw new ArgumentException(\"At least two Query should be passed\");\n\n            var left = queries[0];\n\n            for (int i = 1; i < queries.Length; i++)\n            {\n                left = And(left, queries[i]);\n            }","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Structures/Query.cs#L177-L213","documentation":"Query.And(BsonExpression left, BsonExpression right) combines two filters into '(left AND right)'. At Query.cs:195 it throws ArgumentNullException(nameof(left)) when the left operand is null, because interpolating null.Source would NullReferenceException later. The right operand is checked immediately after at line 196. Both sides must be non-null BsonExpression instances produced by the other Query builders.","triggerScenarios":"Calling Query.And(null, expr) or Query.And(maybeNull, expr) where the left side came from a conditional that returned null. Note this binary overload is also called internally by the params overload, so a null element inside a params array surfaces here too.","commonSituations":"Conditionally building a left filter (e.g. only when a flag is set) that yields null; composing results of helper methods that can return null on empty input.","solutions":["Ensure both operands are non-null before calling: use Query.All() as a neutral identity when a side is optional.","Return Query.All(\"_id\") instead of null from helper builders.","Null-check each operand and short-circuit."],"exampleFix":"// before\nvar q = Query.And(maybeLeft, right); // maybeLeft can be null\n\n// after\nvar left = maybeLeft ?? Query.All(\"_id\");\nvar q = Query.And(left, right);","handlingStrategy":"validation","validationCode":"var safeLeft = left ?? Query.All(\"_id\");\nvar q = Query.And(safeLeft, right);","typeGuard":"static bool IsComposable(BsonExpression e) => e is not null;","tryCatchPattern":null,"preventionTips":["Make filter-builder helpers never return null — use Query.All() as identity.","Null-check operands when composing optional filters.","Use Query.All() as the neutral left operand for conditional ANDs."],"tags":["litedb","query","argument-null","validation","and","composition"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}