{"record":{"id":"fbb987593b891500","repo":"wmjordan/PDFPatcher","slug":"error-fbb987","errorCode":null,"errorMessage":"找不到信息文件。","messagePattern":"找不到信息文件。","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"App/Processor/DocInfoImporter.cs","lineNumber":34,"sourceCode":"\t\treadonly float _unitFactor;\r\n\t\treadonly PdfInfoXmlDocument _infoDoc;\r\n\t\tinternal PdfInfoXmlDocument InfoDoc => _infoDoc;\r\n\r\n\t\treadonly ImporterOptions _options;\r\n\t\t/// <summary>\r\n\t\t/// 从 <see cref=\"XmlDocument\"/> 实例创建导入器（支持无信息文件的补丁操作）。\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"options\">导入器的选项。</param>\r\n\t\t/// <param name=\"infoDoc\">包含信息文件的 <see cref=\"XmlDocument\"/>。</param>\r\n\t\tinternal DocInfoImporter(ImporterOptions options, PdfInfoXmlDocument infoDoc) {\r\n\t\t\t_options = options;\r\n\t\t\t_unitFactor = 1;\r\n\t\t\t_infoDoc = infoDoc;\r\n\t\t}\r\n\r\n\t\tinternal DocInfoImporter(ImporterOptions options, string infoDocFile) {\r\n\t\t\tif (string.IsNullOrEmpty(infoDocFile)) {\r\n\t\t\t\tthrow new FileNotFoundException(\"找不到信息文件。\");\r\n\t\t\t}\r\n\r\n\t\t\tvar infoDoc = new PdfInfoXmlDocument();\r\n\t\t\tif (FileHelper.HasExtension(infoDocFile, Constants.FileExtensions.Txt)) {\r\n\t\t\t\tOutlineManager.ImportSimpleBookmarks(infoDocFile, infoDoc);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tinfoDoc.Load(infoDocFile);\r\n\t\t\t}\r\n\r\n\t\t\t// 设置单位转换因数\r\n\t\t\t_unitFactor = GetUnitFactor(infoDoc.DocumentElement);\r\n\t\t\t_infoDoc = infoDoc;\r\n\t\t\t_options = options;\r\n\t\t}\r\n\r\n\t\tinternal DocInfoImporter(ImporterOptions importerOptions, PdfReader pdf, PatcherOptions patcherOptions, PdfInfoXmlDocument infoDoc) {\r\n\t\t\tvar v = patcherOptions.ViewerPreferences;\r","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/DocInfoImporter.cs#L16-L52","documentation":"DocInfoImporter constructor (the overload taking a file path) throws FileNotFoundException when the infoDocFile argument is null or empty. The string info-file path is required to load bookmark/metadata XML; an empty path is treated as a missing file rather than being silently ignored.","triggerScenarios":"Invoking new DocInfoImporter(options, infoDocFile) with infoDocFile == null or infoDocFile == \"\". This happens when a caller forgets to supply the info file path, passes a variable that was never assigned, or misuses the path-based overload when the XmlDocument-based overload was intended.","commonSituations":"A UI/CLI flow where the user did not select an info file but the code still called the file-path constructor instead of the XmlDocument overload; a null returned from a file-picker dialog passed straight through; refactoring that swapped which constructor is called.","solutions":["Use the (options, PdfInfoXmlDocument) constructor overload when no info file is available (it supports patch operations without an info file).","Validate that infoDocFile is non-null and points to an existing file before calling this constructor.","If the info file is optional in your flow, branch on string.IsNullOrEmpty and pick the appropriate constructor."],"exampleFix":"// before\nvar imp = new DocInfoImporter(options, infoFile); // infoFile may be null\n\n// after\nvar imp = string.IsNullOrEmpty(infoFile)\n  ? new DocInfoImporter(options, new PdfInfoXmlDocument())\n  : new DocInfoImporter(options, infoFile);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(infoDocFile) || !File.Exists(infoDocFile)) {\n    var imp = new DocInfoImporter(options, new PdfInfoXmlDocument());\n} else {\n    var imp = new DocInfoImporter(options, infoDocFile);\n}","typeGuard":"static bool HasInfoFile(string f) => !string.IsNullOrEmpty(f) && File.Exists(f);","tryCatchPattern":null,"preventionTips":["Use the XmlDocument overload when the info file is optional.","Null-check the result of file-picker dialogs before passing the path.","Validate file existence before invoking the path-based constructor."],"tags":["validation","argument","file-not-found","info-file"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}