2

我正在尝试使用 Process.Start() 启动可执行文件。当 exe 没有 DLL 依赖项时,它可以正常工作。但是,当我需要包含 2 个 DLL 时,它就不起作用了。我已尝试设置 WorkingDirectory,并已验证那里存在 2 个必需的 DLL。有任何想法吗?

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "memcached.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = arguments;  //not shown           
startInfo.WorkingDirectory = Environment.CurrentDirectory;

try
  {
    using (Process exeProcess = Process.Start(startInfo))
      {
        exeProcess.WaitForExit();
      }
  }
    catch (Exception ex)
  {
    Trace.TraceError(ex.Message);  // never gets here
  }

这是基于 Windows Azure Memcached 解决方案加速器的代码。当 memcached 无法启动时,会显示一个对话框。不幸的是,当代码在云中远程运行时,您看不到这一点。

4

3 回答 3

3

我在尝试启动另一个需要 DLL 但找不到它的进程时遇到了类似的问题。就我而言,解决方案非常简单,缺少'\'。

procInfo.WorkingDirectory = @"C:\filedir"; //won't work
procInfo.WorkingDirectory = @"C:\filedir\" ; //would do the trick

procInfo.WorkingDirectory = Enviroment.CurrentDirectory; //== "C:\filedir", that won't work either
procInfo.WorkingDirectory = Enviroment.CurrentDirectory + '\\'; // would work.

希望对您有所帮助。

于 2010-08-17T17:25:23.957 回答
1

问题可能是您将 设置为WorkingDirectory当前进程的当前目录(可能在任何地方,不一定是包含您的程序的目录)。尝试将工作目录设置为包含要启动的 exe 的目录。

另外,您是否验证过 DLL 与memcached.exe(或在 所需的位置memcached.exe)?

于 2010-01-16T22:42:00.053 回答
0

尝试将您的 .EXE 文件和引用的程序集放在同一个位置,并将您定义WorkingDirectory.WorkingDirectory到该文件夹​​。这可能会正常工作。

一种极端的替代方法是引用程序集 (DLL) 的强名称并将它们注册到 GAC。

在考虑此选项之前,您应该用尽所有其他选择。

于 2010-01-16T22:47:31.037 回答