C#中调用System.Diagnostics.Process.Start无法打开链接的问题求助
Hey, I’ve dealt with this exact error on Windows 10 and Visual Studio before—let’s walk through the most likely fixes and check other potential issues:
First: Fix the Core .NET Configuration Issue
The #1 reason for this error in modern .NET (Core/.NET 5+) is that the default behavior of Process.Start(string) has changed. When you pass a URL directly, it treats the URL as an executable file path (since UseShellExecute defaults to false), which obviously doesn’t exist.
Here’s the corrected code that forces the system to use your default browser:
using System.Diagnostics; var startInfo = new ProcessStartInfo("http://google.com") { UseShellExecute = true }; Process.Start(startInfo);
This tells the OS to use its default shell (which handles URL-to-browser associations) instead of trying to run the URL as an executable. This should resolve the error in most cases.
If That Doesn’t Work: Check Other Potential Issues
Let’s rule out other scenarios, including your proxy environment suspicion:
- Test the system shell directly: Open Command Prompt and run
start http://google.com. If this fails, the issue is with your system’s ability to open URLs via the shell (not your code). If it works, your code was the problem. - Proxy environment impact: A strict proxy might block the browser from launching or resolving the URL, but this usually throws a different error (like a connection timeout) instead of "file not found". However, you can check your proxy settings in Windows Settings → Network & Internet → Proxy, and ensure your default browser is configured to use the proxy correctly.
- Broken default browser association: Sometimes Windows loses track of which browser to use for URLs. Reset this by going to Settings → Apps → Default Apps, find "Web browser", reselect your preferred browser, then retest your code.
- Visual Studio permissions: Try running Visual Studio as an administrator (right-click → "Run as administrator") and debugging again. Rarely, restricted permissions can prevent the process from launching the shell.
内容的提问来源于stack exchange,提问作者Morta

