{"record":{"id":"79f1f29c52863227","repo":"PowerShell/PowerShell","slug":"pwshpath","errorCode":null,"errorMessage":"{pwshPath}","messagePattern":"\\{pwshPath\\}","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs","lineNumber":52,"sourceCode":"            var arguments = new List<string>(args.Length + 1);\n            var pwshPath = Path.Combine(currentPath, platformFolder, PwshDllName);\n            arguments.Add(pwshPath);\n            arguments.AddRange(args);\n\n            if (File.Exists(pwshPath))\n            {\n                Console.CancelKeyPress += (sender, e) =>\n                {\n                    e.Cancel = true;\n                };\n\n                var process = System.Diagnostics.Process.Start(\"dotnet\", arguments);\n                process.WaitForExit();\n                return process.ExitCode;\n            }\n            else\n            {\n                throw new FileNotFoundException(pwshPath);\n            }\n        }\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":57,"githubUrl":"https://github.com/PowerShell/PowerShell/blob/3ff3c711bf54a18f8440f3c5190c3ac91cdc5852/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs#L34-L57","documentation":"Thrown by the .NET global-tool shim's Main when pwsh.dll is not present at the computed platform folder (./win/pwsh.dll or ./unix/pwsh.dll relative to the entry assembly directory). The tool package was installed but the runtime payload for the current OS is missing, so it cannot launch PowerShell.","triggerScenarios":"Running `pwsh` (dotnet global tool) after a partial/corrupt install; a custom packaging that dropped the win/ or unix/ subfolder; deploying the global-tool nupkg without bundling the OS-specific pwsh.dll.","commonSituations":"dotnet tool install failed mid-way and left a partial layout; the tool was copied by hand without the per-OS folder; a CI image uses a trimmed global tool package.","solutions":["Reinstall the tool: dotnet tool uninstall --global PowerShell then dotnet tool install --global PowerShell.","Verify Path.Combine(toolDir, \"win\"|\"unix\", \"pwsh.dll\") exists after install.","If packaging the tool yourself, ensure both win/pwsh.dll and unix/pwsh.dll are included in the nupkg.","Run from a clean tool directory to rule out a stale partial layout."],"exampleFix":"// before (manual launch)\nProcess.Start(\"dotnet\", pwshPath);\n\n// after\nif (!File.Exists(pwshPath))\n    throw new FileNotFoundException($\"pwsh.dll not found at {pwshPath}. Reinstall the global tool: dotnet tool uninstall -g PowerShell; dotnet tool install -g PowerShell\", pwshPath);\nProcess.Start(\"dotnet\", arguments);","handlingStrategy":"validation","validationCode":"string pwshPath = Path.Combine(toolDir, OperatingSystem.IsWindows() ? \"win\" : \"unix\", \"pwsh.dll\");\nif (!File.Exists(pwshPath))\n    throw new FileNotFoundException($\"pwsh.dll missing at {pwshPath}. Reinstall: dotnet tool uninstall -g PowerShell; dotnet tool install -g PowerShell\", pwshPath);","typeGuard":"static bool PwshPayloadPresent(string toolDir) =>\n    File.Exists(Path.Combine(toolDir, OperatingSystem.IsWindows() ? \"win\" : \"unix\", \"pwsh.dll\"));","tryCatchPattern":"try { return EntryPoint.Main(args); }\ncatch (FileNotFoundException ex) { Console.Error.WriteLine($\"{ex.Message}. Reinstall the global tool.\"); return 1; }","preventionTips":["After dotnet tool install, verify the win/ and unix/ subfolders and pwsh.dll.","In CI, run dotnet tool restore from a clean cache.","Include both OS payloads when authoring a custom global-tool nupkg."],"tags":["powershell","global-tool","deployment","dotnet"],"backgroundTag":null,"analyzedSha":"3ff3c711bf54a18f8440f3c5190c3ac91cdc5852","analyzedAt":"2026-08-13T10:39:10.759Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}