{"record":{"id":"7dfb7a9643b91ac5","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-arrayfield","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'arrayField')","messagePattern":"Value cannot be null\\. \\(Parameter 'arrayField'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Structures/QueryAny.cs","lineNumber":16,"sourceCode":"﻿using LiteDB.Engine;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing static LiteDB.Constants;\n\nnamespace LiteDB\n{\n    public class QueryAny\n    {\n        /// <summary>\n        /// Returns all documents for which at least one value in arrayFields is equal to value\n        /// </summary>\n        public BsonExpression EQ(string arrayField, BsonValue value)\n        {\n            if (arrayField.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(arrayField));\n\n            return BsonExpression.Create($\"{arrayField} ANY = {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents for which at least one value in arrayFields are less tha to value (&lt;)\n        /// </summary>\n        public BsonExpression LT(string arrayField, BsonValue value)\n        {\n            if (arrayField.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(arrayField));\n\n            return BsonExpression.Create($\"{arrayField} ANY < {value ?? BsonValue.Null}\");\n        }\n\n        /// <summary>\n        /// Returns all documents for which at least one value in arrayFields are less than or equals value (&lt;=)\n        /// </summary>\n        public BsonExpression LTE(string arrayField, BsonValue value)","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Structures/QueryAny.cs#L1-L34","documentation":"QueryAny.EQ(string arrayField, BsonValue value) builds '$arrayField ANY = $value', matching documents where at least one element of the array field equals value. At QueryAny.cs:16 it throws ArgumentNullException(nameof(arrayField)) when arrayField is null/empty/whitespace, because the ANY operator needs a concrete array path. This is an instance method on the object returned by Query.Any().","triggerScenarios":"Calling Query.Any().EQ(null, v), Query.Any().EQ(\"\", v), or Query.Any().EQ(\"  \", v). Happens when the array field name is read from a mapping that returned empty.","commonSituations":"Querying a tags/categories array where the field name was parameterized and left blank; forgetting the field is an array path and passing a scalar property name that resolved to empty.","solutions":["Pass the concrete array field: Query.Any().EQ(\"tags\", tag).","Validate the array field name before calling.","Confirm the stored property actually holds a BsonArray so ANY is meaningful."],"exampleFix":"// before\nvar q = Query.Any().EQ(arrField, tag); // arrField may be null\n\n// after\nif (string.IsNullOrWhiteSpace(arrField))\n    throw new ArgumentException(\"Array field required.\", nameof(arrField));\nvar q = Query.Any().EQ(arrField, tag);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(arrayField))\n    throw new ArgumentException(\"Array field required.\", nameof(arrayField));\nvar q = Query.Any().EQ(arrayField, value);","typeGuard":"static bool IsValidArrayField(string f) => !string.IsNullOrWhiteSpace(f);","tryCatchPattern":null,"preventionTips":["Confirm the field stores a BsonArray so the ANY operator is meaningful.","Validate the array-field name before calling Query.Any().* builders.","Keep array-field names in constants separate from scalar fields."],"tags":["litedb","query","argument-null","validation","any","array","field-name"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}