从C#代码运行exe时无法加载文件或程序集
我有一个名为MyExe的可执行文件,它在CMD中运行得非常好,但是当我运行它时,发生了一些错误:从C#代码运行exe时无法加载文件或程序集,c#,.net,C#,.net,我有一个名为MyExe的可执行文件,它在CMD中运行得非常好,但是当我运行它时,发生了一些错误: 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
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);
}
试试看
{
流程=新流程();
process.StartInfo.CreateNoWindow=false;
process.StartInfo.UseShellExecute=false;
process.StartInfo.FileName=exec;
process.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;
如果(args!=null)
{
对于(int idx=0;idx
<>我还试着用C++代码运行exe文件,输出正确。p>
在C#中运行可执行文件时有什么不同吗
顺便说一句,我没有exe文件的源代码
提前感谢。确保您正在本地目录中运行代码。当你从一个网络驱动器中运行时,你可能会在C++中出错,你不在C++中的原生代码中运行。你是否在同一个目录下运行EXE?环境变量不是作为一个进程运行时设置的,所以你需要包括文件的完整路径名。您可以作为cmd.exe运行,文件名作为参数。这可能始终是一个权限问题,请尝试作为运行Visual Studioadministrator@AlexanderHiggins我试过了,没用。你是从本地目录运行的吗?当你从一个网络驱动器中运行时,你可能会在C语言中出错,你不会在C++这样的本地代码中运行。