Search code examples
c#wpfsystem.diagnostics

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


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?


Solution

  • Looking around further, it seems that in .Net Core the UseShellExecute value is defaulted to false. Manually setting it to true fixed the issue. Here is the blog article I used to discover this fix: https://jeremybytes.blogspot.com/2019/08/converting-net-framework-to-net-core.html