{"record":{"id":"509ae9e914ae67da","repo":"litedb-org/LiteDB","slug":"id","errorCode":null,"errorMessage":"id","messagePattern":"id","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Storage/LiteStorage.cs","lineNumber":33,"sourceCode":"        private readonly ILiteDatabase _db;\n        private readonly ILiteCollection<LiteFileInfo<TFileId>> _files;\n        private readonly ILiteCollection<BsonDocument> _chunks;\n\n        public LiteStorage(ILiteDatabase db, string filesCollection, string chunksCollection)\n        {\n            _db = db;\n            _files = db.GetCollection<LiteFileInfo<TFileId>>(filesCollection);\n            _chunks = db.GetCollection(chunksCollection);\n        }\n\n        #region Find Files\n\n        /// <summary>\n        /// Find a file inside datafile and returns LiteFileInfo instance. Returns null if not found\n        /// </summary>\n        public LiteFileInfo<TFileId> FindById(TFileId id)\n        {\n            if (id == null) throw new ArgumentNullException(nameof(id));\n\n            var fileId = _db.Mapper.Serialize(typeof(TFileId), id);\n\n            var file = _files.FindById(fileId);\n\n            if (file == null) return null;\n\n            file.SetReference(fileId, _files, _chunks);\n\n            return file;\n        }\n\n        /// <summary>\n        /// Find all files that match with predicate expression.\n        /// </summary>\n        public IEnumerable<LiteFileInfo<TFileId>> Find(BsonExpression predicate)\n        {\n            var query = _files.Query();","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Storage/LiteStorage.cs#L15-L51","documentation":"ArgumentNullException thrown by LiteStorage<TFileId>.FindById when the id argument is null. The method serializes the id to a BsonValue to look up the file document, so a null id cannot be queried. The generic TFileId could be a reference type (string) allowing null, or a nullable value type.","triggerScenarios":"Calling storage.FindById(null) or storage.FindById(someIdVariable) where someIdVariable is null. Common when TFileId is string and the caller passed an uninitialized or user-supplied value.","commonSituations":"User-supplied file ID from an HTTP request that was missing. A nullable string field used as the file ID. Forgetting to validate input before querying storage.","solutions":["Validate that id is non-null before calling FindById.","Use string.IsNullOrEmpty or a null check for reference-type IDs.","Return a 404/not-found result upstream if the ID is missing rather than passing null to the API."],"exampleFix":"// before\nvar info = storage.FindById(requestedId); // requestedId may be null\n// after\nif (requestedId is null) return NotFound();\nvar info = storage.FindById(requestedId);","handlingStrategy":"validation","validationCode":"if (id is null)\n    return null; // or throw a domain-specific exception\nreturn storage.FindById(id);","typeGuard":"static bool IsValidFileId<T>(T id) => id is not null;","tryCatchPattern":"try\n{\n    var info = storage.FindById(id);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"id\")\n{\n    // id was null; handle the missing-ID case\n}","preventionTips":["Check for null before calling FindById, especially with string or nullable IDs.","Validate user-supplied IDs at the API boundary.","Enable nullable reference types so null IDs are caught at compile time."],"tags":["argument-null","file-storage","find","validation"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}