Process.Start() throws Win32Exception "The specified executable is not a valid application for this OS platform"

1.3k Views Asked by At

I'm trying to make my program open a link to a local HTML file in the user's default browser as a quick way to open a help page for my program. From what I gathered, using Process.Start(path) was the easiest way to do it, but when calling it, I get an exception "The specified executable is not a valid application for this OS platform"

This is the (very quick) code I wrote:

_helpURL = "HelpPage.html"

private static void OpenHelpPage()
{
    Process.Start(_helpURL);
}

However, when the function is called, it throws the following error:

System.ComponentModel.Win32Exception (193): An error occurred trying to start process 'Help Page/HelpPage.html' with working directory 'C:\Users\ ...'. The specified executable is not a valid application for this OS platform.

The directory definitely contains the file in question and I have Chrome set as my default browser for handling .html files.

I haven't been able to find any answers online about getting this error while opening an HTML file this way.

1

There are 1 best solutions below

0
MilliOnTealeaves On BEST ANSWER

Solved it! Used this answer to do it, as suggested by @MostafaMohamedAhmed. Thank you very much :3

Here's the code I ended up using: (_exeUrl is the location of the executable)

private static void OpenHelpPage()
{
    Process p = new()
    {
        StartInfo = new(_exeUrl + _helpUrl)
        { UseShellExecute = true }
    };
    p.Start();
}