使用 System.Diagnostics.Process.Start 运行程序会导致应用程序错误
在我的 PC 上,DWG 文件打开方式为:
"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "%1"
如果我从命令行运行此命令:
"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"
AutoCAD Lite 打开 DWG 文件。
同样,如果我打开命令提示符并使用参数运行相同的 exe,它就可以正常工作。
但是,如果我使用
var proc = new System.Diagnostics.Process();
var info = new System.Diagnostics.ProcessStartInfo();
然后
info.FileName = "C:\Some Path\Test.dwg";
proc.StartInfo = info;
proc.Start();
或
info.FileName = "C:\Program Files\AutoCAD LT 2007\acadlt.exe";
info.Arguments= "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();
或或
info.FileName = "cmd.exe";
info.Arguments= "C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();
我收到以下错误:
acadlt.exe - 应用程序错误
“0x01317c8c”处的指令引用了“0x01317c8c”处的内存。内存无法被“读取”。
单击“确定”终止程序 单击取消调试程序
确定取消
顺便说一句,如果我使用调试器单步执行代码,则代码可以正常工作。
有人知道如何使用 Process.Start 打开此 DWG?
On my PC DWG files open with:
"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "%1"
If I run this from the command line:
"C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"
AutoCAD Lite open the DWG file.
Similarly if I open a command prompt and run the same exe with argument, it works fine.
However if I use
var proc = new System.Diagnostics.Process();
var info = new System.Diagnostics.ProcessStartInfo();
and then
info.FileName = "C:\Some Path\Test.dwg";
proc.StartInfo = info;
proc.Start();
or
info.FileName = "C:\Program Files\AutoCAD LT 2007\acadlt.exe";
info.Arguments= "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();
or
info.FileName = "cmd.exe";
info.Arguments= "C:\Program Files\AutoCAD LT 2007\acadlt.exe" "C:\Some Path\Test.dwg"
proc.StartInfo = info;
proc.Start();
I get the following error:
acadlt.exe - Application Error
The instruction at "0x01317c8c" referenced memory at "0x01317c8c". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
OK Cancel
Incidentally the code works ok if I step through the code with the debugger.
Anyone know how I can use Process.Start to open this DWG?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保指定了正确的工作文件夹:
Make sure to have the correct working folder specified:
从命令行启动和以这种方式使用 ProcessStartInfo 的一个区别是后者 使用 shell 执行。我认为这不太可能导致此问题,但可能会导致问题。尝试添加以下内容并查看是否可以解决问题。
One difference between launching from the command line and using
ProcessStartInfo
in this manner is that the latter uses shell execution. I don't think it's likely to be causing this problem but can cause issues. Try adding the following and seeing if it fixes the problem.事实证明,是 Xenocode Postbuild 导致了应用程序错误。如果我在普通的 .NET exe(未混淆)上运行相同的代码,它可以正常工作。我参考了 Xenocode 的解决方案。
It turns out that it was Xenocode Postbuild causing the Application Error. If I run the same code on a normal .NET exe (not obfuscated), it works fine. I have referred to Xenocode for a solution.