{"record":{"id":"9790f0f433ae1f2d","repo":"netchx/netch","slug":"bin-mainfile-file-not-found","errorCode":null,"errorMessage":"bin\\{mainFile} file not found!","messagePattern":"bin\\\\(.+?) file not found!","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"Netch/Controllers/Guard.cs","lineNumber":25,"sourceCode":"\nnamespace Netch.Controllers;\n\npublic abstract class Guard\n{\n    private FileStream? _logFileStream;\n    private StreamWriter? _logStreamWriter;\n\n    /// <param name=\"mainFile\">application path relative of Netch\\bin</param>\n    /// <param name=\"redirectOutput\"></param>\n    /// <param name=\"encoding\">application output encode</param>\n    protected Guard(string mainFile, bool redirectOutput = true, Encoding? encoding = null)\n    {\n        RedirectOutput = redirectOutput;\n\n        var fileName = Path.GetFullPath($\"bin\\\\{mainFile}\");\n\n        if (!File.Exists(fileName))\n            throw new MessageException(i18N.Translate($\"bin\\\\{mainFile} file not found!\"));\n\n        Instance = new Process\n        {\n            StartInfo =\n            {\n                FileName = fileName,\n                WorkingDirectory = $\"{Global.NetchDir}\\\\bin\",\n                CreateNoWindow = true,\n                UseShellExecute = !RedirectOutput,\n                RedirectStandardOutput = RedirectOutput,\n                StandardOutputEncoding = RedirectOutput ? encoding : null,\n                RedirectStandardError = RedirectOutput,\n                StandardErrorEncoding = RedirectOutput ? encoding : null,\n                WindowStyle = ProcessWindowStyle.Hidden\n            }\n        };\n    }\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Controllers/Guard.cs#L7-L43","documentation":"Thrown by the Guard base constructor when the managed wrapper for an external binary (e.g. pcap2socks.exe, v2ray/xray, other tools under Netch\\bin) cannot be found on disk. Path.GetFullPath($\"bin\\{mainFile}\") is resolved relative to the current working directory (Global.NetchDir), and File.Exists is checked before the Process is even constructed. This is a hard precondition failure: the controller cannot launch its child process.","triggerScenarios":"Constructing any Guard subclass (PcapController passes 'pcap2socks.exe', V2rayController/other controllers pass their binary name) when the named file is absent from Netch\\bin; running Netch from a directory other than Global.NetchDir so the relative path resolves wrong; antivirus deleting the bundled exe.","commonSituations":"Partial extract of a release zip that dropped the bin folder; security software quarantining proxy binaries; building from source without publishing the bin dependencies; moving the Netch folder and leaving bin behind.","solutions":["Confirm the file exists: check Netch\\bin\\<mainFile> in File Explorer or with File.Exists at the resolved full path.","Re-download/re-extract the official release so the complete bin directory is present.","If antivirus removed it, add an exclusion for the Netch directory and restore the file.","Ensure Global.NetchDir (and the process working directory) is the folder that actually contains bin\\."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"string resolved = Path.GetFullPath(Path.Combine(Global.NetchDir, \"bin\", mainFile));\nif (!File.Exists(resolved))\n    throw new FileNotFoundException($\"Required binary missing: {resolved}\", resolved);","typeGuard":null,"tryCatchPattern":"try { controller = new SomeGuard(\"tool.exe\"); }\ncatch (MessageException ex) when (ex.Message.Contains(\"file not found!\"))\n{\n    // surface a repair prompt / offer to re-download the bin folder\n    NotifyUser(\"Netch installation is incomplete: bin\\\\\" + mainFile + \" missing.\");\n}","preventionTips":["Run a startup self-check that verifies all expected bin\\ entries exist before enabling controllers.","Ship a checksums file and validate the bin directory on launch to detect AV deletion.","Resolve all paths against Global.NetchDir explicitly rather than the process working directory.","Add an antivirus exclusion guidance step to first-run."],"tags":["file-system","binary-dependency","startup","native-interop"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}