{"record":{"id":"962567a0384ef880","repo":"JosefNemec/Playnite","slug":"emulator-executable-not-found-path-in-workdir","errorCode":null,"errorMessage":"Emulator executable not found.\n\n{path} in {workDir}","messagePattern":"Emulator executable not found\\.\n\n(.+?) in (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"source/Playnite/Controllers/GenericGameController.cs","lineNumber":251,"sourceCode":"            startedRomFile = romPath;\r\n            startedEmulator = emulator;\r\n            startedEmulatorProfile = emuProfile;\r\n            startedEmulatorDir = emulatorDir;\r\n\r\n            if (asyncExec)\r\n            {\r\n                ExecuteEmulatorScript(currentEmuProfile.PreScript, emulatorDir, romPath, emulator, emuProfile);\r\n                Process process = null;\r\n                try\r\n                {\r\n                    process = ProcessStarter.StartProcess(path, args, workDir);\r\n                }\r\n                catch (Win32Exception exc)\r\n                {\r\n                    // 2 is ERROR_FILE_NOT_FOUND\r\n                    if (exc.NativeErrorCode == 2)\r\n                    {\r\n                        throw new FileNotFoundException(LOC.ErrorEmulatorExecutableNotFound.GetLocalized() +\r\n                            $\"\\n\\n{path} in {workDir}\");\r\n                    }\r\n                    else\r\n                    {\r\n                        throw;\r\n                    }\r\n                }\r\n\r\n                void gameStarted(int processId)\r\n                {\r\n                    startedEmuProcessId = processId;\r\n                    ExecuteEmulatorScript(currentEmuProfile.PostScript, emulatorDir, romPath, emulator, emuProfile);\r\n                    InvokeOnStarted(new GameStartedEventArgs { StartedProcessId = startedEmuProcessId });\r\n                }\r\n\r\n                if (trackingMode == TrackingMode.Default || trackingMode == TrackingMode.Process)\r\n                {\r\n                    gameStarted(process.Id);\r","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/Controllers/GenericGameController.cs#L233-L269","documentation":"Thrown as FileNotFoundException when ProcessStarter.StartProcess raises a Win32Exception with NativeErrorCode 2 (ERROR_FILE_NOT_FOUND) at process launch time. Unlike error 40 which fires before launch (regex match failed), this fires at the OS level: the resolved path existed in theory but Windows could not find the executable when actually spawning the process.","triggerScenarios":"StartEmulatorProcess is called in async mode (asyncExec=true); ProcessStarter.StartProcess(path, args, workDir) internally calls Process.Start and the OS returns ERROR_FILE_NOT_FOUND (Win32 error 2). The path may have been valid when checked but became inaccessible, or the working directory is invalid.","commonSituations":"The executable was deleted or moved between resolution and launch. The working directory (workDir) does not exist. The path points to a UNC path or mapped drive that became unavailable. A symlink or junction target is broken. Anti-virus quarantined the executable. The path contains environment variables that resolve differently in the process context.","solutions":["Verify the executable file exists at the resolved path shown in the error message at the moment of launch.","Check that the working directory exists: the workDir in the error must be a valid folder.","If using mapped drives or UNC paths, ensure the network resource is accessible from the Playnite process.","Temporarily disable anti-virus or add an exclusion for the emulator directory.","Re-derive the path using Emulation.GetExecutable to get a fresh match, or switch to a custom profile with a hardcoded path."],"exampleFix":"// before — path resolves but OS can't find it at spawn\nprocess = ProcessStarter.StartProcess(path, args, workDir);\n\n// after — validate existence immediately before spawning\nif (!File.Exists(path))\n    throw new FileNotFoundException($\"Executable vanished before launch: {path}\");\nif (!Directory.Exists(workDir))\n    throw new DirectoryNotFoundException($\"Working directory does not exist: {workDir}\");\nprocess = ProcessStarter.StartProcess(path, args, workDir);","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(path) || !Directory.Exists(workDir))\n{\n    logger.Error($\"Cannot start: path={path}, workDir={workDir}\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    process = ProcessStarter.StartProcess(path, args, workDir);\n}\ncatch (Win32Exception ex) when (ex.NativeErrorCode == 2)\n{\n    logger.Error($\"File not found at launch: {path} in {workDir}. Ex: {ex.Message}\");\n    // retry with re-resolved path or notify user\n}","preventionTips":["Validate file and directory existence immediately before Process.Start, not just during configuration.","Pin emulator and game paths to verified locations; avoid paths with environment variables that may resolve differently.","Monitor for antivirus quarantine of game executables."],"tags":["emulator","win32","process-start","file-not-found","executable-path"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}