{"record":{"id":"cc1317979a3b1003","repo":"litedb-org/LiteDB","slug":"value-cannot-be-null-parameter-array","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'array')","messagePattern":"Value cannot be null\\. \\(Parameter 'array'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Document/BsonArray.cs","lineNumber":19,"sourceCode":"﻿using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Linq;\nusing static LiteDB.Constants;\n\nnamespace LiteDB\n{\n    public class BsonArray : BsonValue, IList<BsonValue>\n    {\n        public BsonArray()\n            : base(BsonType.Array, new List<BsonValue>())\n        {\n        }\n\n        public BsonArray(List<BsonValue> array)\n            : 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);","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Document/BsonArray.cs#L1-L37","documentation":"Thrown by the BsonArray(List<BsonValue>) constructor when the supplied list is null. The constructor copies the list contents into the array's backing storage, so a null source has nothing to enumerate. The guard fires before AddRange is attempted.","triggerScenarios":"Calling new BsonArray((List<BsonValue>)null); passing a list from a LINQ query that returned null; converting a nullable list field directly into the constructor.","commonSituations":"Mapping nullable collection properties from DTOs into BsonArray; deserializing optional array fields that were absent; refactoring that left a list uninitialized.","solutions":["Pass a non-null list or use the parameterless constructor followed by AddRange.","Coalesce null lists to an empty list at the source.","Guard collection-producing logic to never return null."],"exampleFix":"// before\nvar arr = new BsonArray(myList);\n\n// after\nvar arr = new BsonArray(myList ?? new List<BsonValue>());","handlingStrategy":"validation","validationCode":"var arr = new BsonArray(list ?? new List<BsonValue>());","typeGuard":"static bool IsNonNullList(List<BsonValue> l) => l is not null;","tryCatchPattern":null,"preventionTips":["Coalesce nullable lists to empty at the source.","Prefer the parameterless constructor plus AddRange for optional data.","Ensure collection-producing methods never return null."],"tags":["argument-validation","bson","bsonarray","null-check","constructor"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}