You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET6下使用DevExpress导出GridView到Excel报Win32Exception错误如何解决

异常触发原因

.NET 6属于.NET Core技术栈,System.Diagnostics.Process的默认运行逻辑和.NET Framework存在核心差异:

  • .NET Framework中Process.Start(string fileName)的UseShellExecute参数默认值为true,系统会自动调用Shell层处理非可执行文件,根据后缀名的关联规则调用对应默认程序打开文档
  • .NET Core及后续版本(包含.NET 6)中UseShellExecute默认值为false,运行时会直接将传入的路径当做可执行文件尝试启动,你传入的xlsx是文档文件而非可执行程序,因此抛出“指定的可执行文件不是此OS平台的有效应用程序”错误。

修复方案

修改打开导出文件的代码,显式指定UseShellExecute = true即可还原.NET Framework的兼容行为,替换原有代码即可:

//Try to open the file and let windows decide how to open it.
System.Diagnostics.Process.Start(new ProcessStartInfo(exportFilePath)
{
    UseShellExecute = true
});

内容的提问来源于stack exchange,提问作者M.Bouabdallah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 12:00:01