WPF Using .Net 3.1 - Process.Start Excel File Error: "The specified executable is not a valid application for this OS platform."

Viewed 1249

I am trying to open an Excel file (.xlsx) within a WPF .NET Core 3.1 app. Using Winforms, I am able to do

process.start("Resources/test.xlsx")

and the file will open.

In the WPF application doing the same thing results in an error

The specified executable is not a valid application for this OS platform

I am using the same code and opening the same file using both apps. Only the Winforms app will work, WPF will throw that error.

Is there a new way of opening files is handled using System.Diagnostics.Process.Start in .Net 3?

2 Answers

Something likes this

private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
{
    // Old way (.NET Framework 4.8)
    // string path = "Resources/test.xlsx";
    // Process.Start(path);

    // New way (.NET 6)
    ProcessStartInfo psInfo = new ProcessStartInfo
    {
        FileName = "Resources/test.xlsx",
        UseShellExecute = true
    };
    Process.Start(psInfo);
}
Related