Running a program with System.Diagnostics.Process.Start causes an Application Error

十年热恋 提交于 2019-12-10 19:44:43

问题


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?


回答1:


Make sure to have the correct working folder specified:

info.WorkingDirectory = "same path as current directory in cmd.exe";



回答2:


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.

info.UseShellExecute = false;



回答3:


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.



来源:https://stackoverflow.com/questions/3972965/running-a-program-with-system-diagnostics-process-start-causes-an-application-er

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!