6

In .NET Framework I can simply do Process.Start(filename); butin .NET Core I get this exception:

System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'

How can I start testfile.txt with my default app? Thank you!

Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35
BDevGW
  • 347
  • 3
  • 15
  • 1
    Does this answer your question? [How do I start a process from C#?](https://stackoverflow.com/questions/181719/how-do-i-start-a-process-from-c) – Barns Feb 01 '20 at 16:33
  • 1
    @Barns while related, I think these are completely different questions – Ismael Padilla Feb 01 '20 at 16:35
  • 1
    It is completely different. In your question it's about starting an executable while I want to open a non executeable file with the default app (without starting the defualt app directly) – BDevGW Feb 01 '20 at 16:39
  • 3
    This is because `UseShellExcute` by default is set to `true` in .NET Framework and `false` in .NET Core – Pavel Anikhouski Feb 01 '20 at 16:41
  • well, how about these examples: [.Net Core 2.0 Process.Start throws...](https://stackoverflow.com/questions/46808315/net-core-2-0-process-start-throws-the-specified-executable-is-not-a-valid-appl) OR [C# Execute Application Using Process.Sta...](https://stackoverflow.com/questions/51153242/c-sharp-execute-application-using-process-start-as-params-to-cmd-and-active-re) Or even [The specified executable is not a valid application for this OS platform.](https://stackoverflow.com/questions/57638802/the-specified-executable-is-not-a-valid-application-for-this-os-platform) – Barns Feb 01 '20 at 16:48

1 Answers1

18

Open it like such:

new Process
{
    StartInfo = new ProcessStartInfo(filename)
    {
        UseShellExecute = true
    }
}.Start();
Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35