Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为使用进程启动的exe指定DLL。是否启动?_C#_Dependencies_Exe_Process.start - Fatal编程技术网

C# 为使用进程启动的exe指定DLL。是否启动?

C# 为使用进程启动的exe指定DLL。是否启动?,c#,dependencies,exe,process.start,C#,Dependencies,Exe,Process.start,我正在尝试使用Process.Start()启动可执行文件。当exe没有DLL依赖项时,它可以正常工作。但是,当我需要包含2个DLL时,它就不起作用了。我已经尝试设置WorkingDirectory,并验证了那里存在2个必需的DLL。有什么想法吗 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = false; star

我正在尝试使用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
  }

这是。当memcached无法启动时,将显示一个对话框。不幸的是,当代码在云中远程运行时,您无法看到这一点。

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


另外,您是否已验证DLL是否与
memcached.exe一起(或位于
memcached.exe
所需的位置)?

尝试将您的.exe文件和引用的程序集放置在同一位置,并将您的
工作目录.WorkingDirectory
定义到该文件夹中。这可能会很好

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


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

我在尝试启动另一个需要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.

希望这对您有所帮助。

我原以为Process.Start()在azure中太难保护,他们会禁用它吗?Azure不提供一个神奇的缓存作为它的API的一部分吗?请注意,我不知道,我很好奇。Spence:MicrosoftAppFabric缓存,又名“Velocity”,是他们的分布式缓存,但它在Azure中还不能工作。现在你可以在Azure中运行任何你想运行的东西,只要它不需要管理员权限。当你在云中编程时,你怎么知道雨从哪里来?谢谢你的想法
Environment.CurrentDirectory
是E:\approot,我已经验证了exe和DLL都存在。Ok。我不确定是指DLL与您的程序一起使用,还是与您想要启动的exe一起使用。不幸的是,我认为我们无法将DLL安装到Azure中的GAC中。是的,我已将exe和DLL放在同一文件夹中。谢谢你的想法。因为这看起来很简单,我想知道我是否真的遇到了与我最初所想的不同的问题。