1

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.

  • Take a look a [this](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute?view=net-8.0). – Alessandro D'Andria May 02 '23 at 08:15
  • Have u checked this answer https://stackoverflow.com/questions/46808315/net-core-2-0-process-start-throws-the-specified-executable-is-not-a-valid-appl – Mostafa Mohamed Ahmed May 03 '23 at 02:16
  • @MostafaMohamedAhmed Thank you, I had read it before but I didn't realise it applied in my situation. Used that method and everything works as intended! – MilliOnTealeaves May 04 '23 at 05:06

1 Answers1

0

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();
}