{"record":{"id":"c33cda887122dfd3","repo":"litedb-org/LiteDB","slug":"name","errorCode":null,"errorMessage":"name","messagePattern":"name","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteDatabase.cs","lineNumber":140,"sourceCode":"            return this.GetCollection<T>(null);\n        }\n\n        /// <summary>\n        /// Get a collection using a name based on typeof(T).Name (BsonMapper.ResolveCollectionName function)\n        /// </summary>\n        public ILiteCollection<T> GetCollection<T>(BsonAutoId autoId)\n        {\n            return this.GetCollection<T>(null, autoId);\n        }\n\n        /// <summary>\n        /// Get a collection using a generic BsonDocument. If collection does not exist, create a new one.\n        /// </summary>\n        /// <param name=\"name\">Collection name (case insensitive)</param>\n        /// <param name=\"autoId\">Define autoId data type (when document contains no _id field)</param>\n        public ILiteCollection<BsonDocument> GetCollection(string name, BsonAutoId autoId = BsonAutoId.ObjectId)\n        {\n            if (name.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(name));\n\n            return new LiteCollection<BsonDocument>(name, autoId, _engine, _mapper);\n        }\n\n        #endregion\n\n        #region Transaction\n\n        /// <summary>\n        /// Initialize a new transaction. Transaction are created \"per-thread\". There is only one single transaction per thread.\n        /// Return true if transaction was created or false if current thread already in a transaction.\n        /// </summary>\n        public bool BeginTrans() => _engine.BeginTrans();\n\n        /// <summary>\n        /// Commit current transaction\n        /// </summary>\n        public bool Commit() => _engine.Commit();","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteDatabase.cs#L122-L158","documentation":"ArgumentNullException thrown by LiteDatabase.GetCollection(string name, BsonAutoId) when name is null, empty, or whitespace (checked via IsNullOrWhiteSpace). The BsonDocument collection overload requires an explicit collection name, unlike the generic overload which derives the name from typeof(T).Name.","triggerScenarios":"Calling db.GetCollection(null) or db.GetCollection(\"\") / db.GetCollection(\"   \") for the BsonDocument overload; a variable-driven collection name that resolved to empty at runtime.","commonSituations":"Dynamic collection naming where the name source is unset; confusing the BsonDocument overload (requires name) with the generic GetCollection<T>() (name optional); trailing whitespace from input trimming.","solutions":["Pass a non-empty collection name: db.GetCollection(\"customers\").","If the name is dynamic, validate/coalesce it before calling GetCollection.","Use the generic overload db.GetCollection<T>() if you want the name derived from the entity type."],"exampleFix":"// before\nvar col = db.GetCollection(name); // name is null\n\n// after\nvar safeName = string.IsNullOrWhiteSpace(name) ? \"default\" : name.Trim();\nvar col = db.GetCollection(safeName);","handlingStrategy":"validation","validationCode":"string safeName = string.IsNullOrWhiteSpace(name)\n    ? throw new ArgumentException(\"Collection name is required.\", nameof(name))\n    : name.Trim();\nvar col = db.GetCollection(safeName);","typeGuard":"static bool IsValidCollectionName(string name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":null,"preventionTips":["Validate collection names at the input boundary before calling GetCollection.","Use the generic GetCollection<T>() overload when you want the type-derived name.","Trim user-supplied names before use."],"tags":["collection","argumentnull","validation","getcollection"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}