{"record":{"id":"b7e1a6d57ef0b980","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-items","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'items')","messagePattern":"Value cannot be null\\. \\(Parameter 'items'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Document/BsonArray.cs","lineNumber":35,"sourceCode":"            : this()\n        {\n            if (array == null) throw new ArgumentNullException(nameof(array));\n\n            this.AddRange(array);\n        }\n\n        public BsonArray(params BsonValue[] array)\n            : this()\n        {\n            if (array == null) throw new ArgumentNullException(nameof(array));\n\n            this.AddRange(array);\n        }\n\n        public BsonArray(IEnumerable<BsonValue> items)\n            : this()\n        {\n            if (items == null) throw new ArgumentNullException(nameof(items));\n\n            this.AddRange(items);\n        }\n        \n        public BsonArray(BsonArray items)\n            : this()\n        {\n            if (items == null) throw new ArgumentNullException(nameof(items));\n\n            this.AddRange(items);\n        }\n\n        public new IList<BsonValue> RawValue => (IList<BsonValue>)base.RawValue;\n\n        public override BsonValue this[int index]\n        {\n            get\n            {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Document/BsonArray.cs#L17-L53","documentation":"Thrown by the BsonArray(IEnumerable<BsonValue>) constructor when items is null. The constructor iterates the sequence to populate the backing list, so a null enumerable cannot be enumerated. The guard ensures a clear ArgumentNullException rather than a downstream NRE.","triggerScenarios":"Calling new BsonArray((IEnumerable<BsonValue>)null); passing a LINQ Where/Select result that is null due to a broken source; converting a nullable enumerable property.","commonSituations":"Mapping LINQ projections that may be null; optional collection fields in domain models; generics where the caller passed default(IEnumerable<BsonValue>).","solutions":["Coalesce the enumerable to Enumerable.Empty<BsonValue>() before constructing.","Ensure LINQ sources are non-null.","Use the parameterless constructor plus AddRange when the source is conditionally available."],"exampleFix":"// before\nvar arr = new BsonArray(items);\n\n// after\nvar arr = new BsonArray(items ?? Enumerable.Empty<BsonValue>());","handlingStrategy":"validation","validationCode":"var arr = new BsonArray(items ?? Enumerable.Empty<BsonValue>());","typeGuard":"static bool IsNonNullEnumerable<T>(IEnumerable<T> e) => e is not null;","tryCatchPattern":null,"preventionTips":["Coalesce enumerables to Enumerable.Empty<T>() before constructing.","Ensure LINQ sources are non-null.","Return empty sequences rather than null from collection methods."],"tags":["argument-validation","bson","bsonarray","null-check","constructor","enumerable"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}