{"record":{"id":"6fa18cb39614651e","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-field","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'field')","messagePattern":"Value cannot be null\\. \\(Parameter 'field'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Structures/Query.cs","lineNumber":89,"sourceCode":"            return BsonExpression.Create($\"{field} < {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents that value are less than or equals value (&lt;=)\n        /// </summary>\n        public static BsonExpression LTE(string field, BsonValue value)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return BsonExpression.Create($\"{field} <= {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all document that value are greater than value (&gt;)\n        /// </summary>\n        public static BsonExpression GT(string field, BsonValue value)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return BsonExpression.Create($\"{field} > {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents that value are greater than or equals value (&gt;=)\n        /// </summary>\n        public static BsonExpression GTE(string field, BsonValue value)\n        {\n            if (field.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(field));\n\n            return BsonExpression.Create($\"{field} >= {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all document that values are between \"start\" and \"end\" values (BETWEEN)\n        /// </summary>\n        public static BsonExpression Between(string field, BsonValue start, BsonValue end)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Structures/Query.cs#L71-L107","documentation":"Query.GT(string field, BsonValue value) builds a BsonExpression '$field > $value' for a greater-than filter. At Query.cs:89 it throws ArgumentNullException(nameof(field)) when field is null, empty, or whitespace, because the field path is required to form the comparison. The check uses IsNullOrWhiteSpace, so blank strings are rejected identically to null. LiteDB throws on the API boundary to surface the real defect.","triggerScenarios":"Calling Query.GT(null, min), Query.GT(\"\", min), or Query.GT(\" \", min). Common when the field name is computed from data and the computation produced no output.","commonSituations":"A dynamic sort/filter builder that derives the field from a runtime alias mapping where the alias was missing; passing a value into the field slot by mistake.","solutions":["Use a concrete field path: Query.GT(\"amount\", threshold).","Resolve/validate the alias to a real field name before calling Query.GT.","Unit-test filter builders with empty/null inputs to catch the regression early."],"exampleFix":"// before\nvar q = Query.GT(resolved ?? \"\", threshold);\n\n// after\nif (string.IsNullOrWhiteSpace(resolved))\n    throw new InvalidOperationException(\"Unknown filter alias.\");\nvar q = Query.GT(resolved, threshold);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(field))\n    throw new InvalidOperationException(\"Field alias could not be resolved.\");\nvar q = Query.GT(field, value);","typeGuard":"static bool IsValidField(string field) => !string.IsNullOrWhiteSpace(field);","tryCatchPattern":null,"preventionTips":["Resolve runtime aliases to concrete field names before building queries.","Reject unresolved aliases with a clear domain error.","Test alias resolution paths with missing mappings."],"tags":["litedb","query","argument-null","validation","field-name"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}