An error occurred trying to start process 'D:\soft\ZQYM\ZQYM1400Grafting\bin\Debug\net6.0-windows\HELP/Scania 11 , 12&16L.pdf' with working directory 'D:\soft\ZQYM\ZQYM1400Grafting\bin\Debug\net6.0-windows'. The specified executable is not a valid application for this OS platform.
指定的可执行文件不是此操作系统的有效应用程序 平台。
无论是把exe换成pdf还是txt都是这样的问题
经查阅得知:
.net framework 与.net 5中发生了一些变化
在 .NET 5以上,UseShellExecute
默认值的更改默认值为 false。在 .NET Framework 上,其默认值为 true。
允许您直接启动应用程序,例如,使用启动 Paint 之类的代码。如果设置为 true,它还允许您间接启动关联的应用程序。在 .NET Framework 上,默认值为 true,这意味着如果已将.txt文件与该编辑器关联,则代码将启动记事本。若要防止在 .NET Framework 上间接启动应用,必须显式设置为 false。在 .NET Core 上,默认值为 false。这意味着,默认情况下,当您调用 时,不会启动关联的应用程序。
var processStartInfo = new ProcessStartInfo
{
FileName = @"你的路径",
UseShellExecute = true
};
Process.Start(processStartInfo);
更改后成功!