{"record":{"id":"0686e99037728408","repo":"OdysseusYuan/LKY_OfficeTools","slug":"file-path","errorCode":null,"errorMessage":"执行 {file_path} 异常！","messagePattern":"执行 (.+?) 异常！","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LKY_OfficeTools/Common/Com_ExeOS.cs","lineNumber":29,"sourceCode":"using static LKY_OfficeTools.Lib.Lib_AppLog;\n\nnamespace LKY_OfficeTools.Common\n{\n    internal class Com_ExeOS\n    {\n        internal class Run\n        {\n            internal static int Exe(string file_path, string args)\n            {\n                try\n                {\n                    Process p = new Process();\n                    var result = Process(file_path, args, out p, true);     //默认等待完成\n\n                    //是否执行了\n                    if (!result)\n                    {\n                        throw new Exception($\"执行 {file_path} 异常！\");\n                    }\n\n                    return p.ExitCode;\n                }\n                catch (Exception Ex)\n                {\n                    new Log(Ex.ToString());\n                    return -920921;\n                }\n            }\n\n            internal static bool Process(string file_path, string args, out Process ProcessInfo, bool WaitForExit)\n            {\n                try\n                {\n                    Console.ForegroundColor = ConsoleColor.Gray;\n\n                    ProcessInfo = new Process();","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/OdysseusYuan/LKY_OfficeTools/blob/6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf/LKY_OfficeTools/Common/Com_ExeOS.cs#L11-L47","documentation":"Thrown by Com_ExeOS.Run.Exe when its private Process() helper returns false, meaning Process.Start() raised a Win32Exception while trying to launch file_path (Com_ExeOS.cs:24). The exception is caught inside Exe itself, logged via Lib_AppLog, and the method returns the sentinel -920921 (Com_ExeOS.cs:37), so callers observe failure as a return value, not a propagating throw. The interpolated file_path identifies exactly which executable failed to start.","triggerScenarios":"Calling Run.Exe(path, args) where path does not exist, is not a valid PE executable, has missing native DLL dependencies, the wrong bitness for the host, or is blocked by AppLocker/SmartScreen/antivirus. Also when UseShellExecute=false and the account lacks execute permission on the file.","commonSituations":"A bundled helper binary was not copied next to the assembly on deploy; a path containing spaces was passed unquoted; a 32-bit-only tool launched on ARM64 without emulation; antivirus quarantined the exe after a signature update.","solutions":["Before calling, verify the target with File.Exists(file_path) and confirm it is a real executable.","Normalize the path with Path.GetFullPath and ensure it is quoted/escaped correctly for the shell context.","Match the executable's bitness to the host process (or force x86/x96 via the project's Platform target).","Reproduce by launching the same file_path from cmd.exe to read the underlying Win32 error code.","If the target needs elevation, run the host process elevated or use ProcessStartInfo.Verb = \"runas\"."],"exampleFix":"// before\nint code = Com_ExeOS.Run.Exe(toolPath, args);\n\n// after\nif (!System.IO.File.Exists(toolPath)) { /* report missing tool, abort */ return; }\nint code = Com_ExeOS.Run.Exe(toolPath, args);\nif (code == -920921) { /* launch failed; details already written to log */ }","handlingStrategy":"validation","validationCode":"const int RUN_FAILED = -920921;\nif (!File.Exists(file_path)) { /* report missing tool */ return; }\nint code = Com_ExeOS.Run.Exe(file_path, args);\nif (code == RUN_FAILED) { /* launch failed; details in Lib_AppLog */ }","typeGuard":"static bool CanLaunch(string path) => !string.IsNullOrWhiteSpace(path) && File.Exists(path);","tryCatchPattern":null,"preventionTips":["Always normalize and verify file_path with Path.GetFullPath + File.Exists before launching.","Treat the -920921 sentinel from Run.Exe as a hard launch failure and surface it to the operator.","Match the executable bitness to the host process to avoid Win32 start errors.","Keep bundled helper binaries copied next to the assembly as part of the build/deploy step."],"tags":["process-launch","win32","executable","process"],"backgroundTag":null,"analyzedSha":"6f9a1bd471918f3310e6be4a6d7f42d0d6e467cf","analyzedAt":"2026-08-13T18:00:34.810Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}