我有一个名为MyExe的可执行文件,并且在CMD中运行完美,但是当我运行C#时,发生了一些错误:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cef71ad57bad51d2' or one of its dependencies. The system cannot find the file specified. at MyExe.Program.Main(String[] args)
这是我运行exe文件的代码。
try
{
Process process = new Process();
process.StartInfo.CreateNoWindow = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = exec;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (args != null)
{
for (int idx = 0; idx < args.Length; ++idx)
{
if (idx == 0) process.StartInfo.Arguments = args[idx];
else process.StartInfo.Arguments += " " + args[idx];
}
}
Console.WriteLine(process.StartInfo.Arguments);
process.Start();
process.WaitForExit();
Console.WriteLine("Complete!");
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
我也试过用C ++代码运行exe文件,输出正确。
在C#中运行可执行文件时有什么不同吗?
顺便说一下,我没有exe文件的源代码。
提前致谢。
答案 0 :(得分:1)
确保从本地目录运行代码。从C语言本机代码中运行的网络驱动器运行时,您可能会在C#中遇到错误。