{"record":{"id":"e115f869bee6a3c6","repo":"litedb-org/LiteDB","slug":"filename","errorCode":null,"errorMessage":"filename","messagePattern":"filename","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Storage/LiteFileInfo.cs","lineNumber":80,"sourceCode":"        /// <summary>\n        /// Copy file content to another stream\n        /// </summary>\n        public void CopyTo(Stream stream)\n        {\n            if (stream == null) throw new ArgumentNullException(nameof(stream));\n\n            using (var reader = this.OpenRead())\n            {\n                reader.CopyTo(stream);\n            }\n        }\n\n        /// <summary>\n        /// Save file content to a external file\n        /// </summary>\n        public void SaveAs(string filename, bool overwritten = true)\n        {\n            if (filename.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(filename));\n\n            using (var file = File.Open(filename, overwritten ? FileMode.Create : FileMode.CreateNew))\n            {\n                using (var stream = this.OpenRead())\n                {\n                    stream.CopyTo(file);\n                }\n            }\n        }\n    }\n}","sourceCodeStart":62,"sourceCodeEnd":91,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Storage/LiteFileInfo.cs#L62-L91","documentation":"ArgumentNullException thrown by LiteFileInfo<TFileId>.SaveAs when the filename argument is null, empty, or whitespace. The method uses IsNullOrWhiteSpace (a LiteDB extension) for the check, so any blank string is rejected. SaveAs opens a file on disk and writes all stored chunks to it.","triggerScenarios":"Calling file.SaveAs(null), file.SaveAs(\"\"), or file.SaveAs(\"   \"). Also triggered when filename is computed from user input or a database field that turned out to be blank.","commonSituations":"Reading the filename from a configuration value that was not set. Generating the path from a format string where a component was null/empty. Passing a property from a deserialized object that defaulted to null.","solutions":["Validate the filename is a non-empty, valid path before calling SaveAs.","Use Path.Combine to build the full path from known components.","Provide a fallback filename when the source is null."],"exampleFix":"// before\nfile.SaveAs(filePath); // filePath may be null/empty\n// after\nif (!string.IsNullOrWhiteSpace(filePath))\n    file.SaveAs(filePath);\nelse\n    throw new InvalidOperationException(\"Export path was not configured.\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(filename))\n    throw new ArgumentException(\"Filename is required.\", nameof(filename));\nfile.SaveAs(filename);","typeGuard":"static bool IsValidFilename(string f) => !string.IsNullOrWhiteSpace(f) && f.IndexOfAny(Path.GetInvalidPathChars()) < 0;","tryCatchPattern":"try\n{\n    file.SaveAs(path);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"filename\")\n{\n    // path was null/empty; provide a valid path\n    throw;\n}","preventionTips":["Validate the filename/path is non-empty before calling SaveAs.","Build paths with Path.Combine from known, validated components.","Enable nullable reference types and mark filename parameters as non-nullable."],"tags":["argument-null","file-storage","saveas","validation"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}