Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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# ProcessStartInfo.WorkingDirectory可以';找不到服务器上的位置_C#_.net - Fatal编程技术网

C# ProcessStartInfo.WorkingDirectory可以';找不到服务器上的位置

C# ProcessStartInfo.WorkingDirectory可以';找不到服务器上的位置,c#,.net,C#,.net,我有一个非常奇怪的情况 在我们公司,我们开发了由几个模块组成的大型web应用程序。每个模块都划分在服务器上的单独文件夹中。有一个模块可以启动映射到用户L:\app.exe磁盘上的应用程序 我的目标是更新调用方法,该方法首先将启动模块内的switcher.exe文件,然后将像以前一样启动L:\app.exe 问题是,当我在本地构建此模块时,它工作得非常好,但当我从服务器上的bin\Debugg(包括swither.exe)下载内容时(比如在Dev环境中),应用程序无法在服务器上的文件夹中找到“sw

我有一个非常奇怪的情况

在我们公司,我们开发了由几个模块组成的大型web应用程序。每个模块都划分在服务器上的单独文件夹中。有一个模块可以启动映射到用户L:\app.exe磁盘上的应用程序

我的目标是更新调用方法,该方法首先将启动模块内的switcher.exe文件,然后将像以前一样启动L:\app.exe

问题是,当我在本地构建此模块时,它工作得非常好,但当我从服务器上的bin\Debugg(包括swither.exe)下载内容时(比如在Dev环境中),应用程序无法在服务器上的文件夹中找到“switcher.exe”。它抛出一个异常,表示{“系统找不到指定的文件”}

背后的代码非常简单:

private void LaunchSwitherExe()
        { 
            string executionPath = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            MessageBox.Show(executionPath);  

            Process themeSwitchProc = new Process();

            themeSwitchProc.StartInfo.FileName = "Switcher.exe";
            themeSwitchProc.StartInfo.WorkingDirectory = executionPath;


            themeSwitchProc.Start();
         }
messagebox(出于测试目的)显示swither.exe的路径。这条路是绝对正确的。它里面有swither.exe

你有什么想法吗

---更新---

问题将在字符串中找到路径。这:

string executionPath = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
更改为:

string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Directory.SetCurrentDirectory(exeDir);

感谢所有回答问题的人,特别是“Rick S.”

您是否考虑过这可能是权限问题?代码在哪个进程Id下运行,它是否有权访问该文件夹

我还发现:

When the UseShellExecute property is false, gets or sets the working directory for the
process to be started. When UseShellExecute is true, gets or sets the directory that
contains the process to be started.
也许可以试试这个:

您是否在IIS或IISExpress或类似的系统中运行?是的。它在IIS下运行。您应该检查应用程序运行的应用程序池是否具有访问“switcher.exe”文件的权限。非常感谢。你的链接有帮助。问题出现在字符串exeDir=Path.GetDirectoryName(Assembly.getExecutionGassembly().Location)中;SetCurrentDirectory(exeDir);非常感谢你!你帮了我的忙。问题出在路径的字符串中,我将其更改为此链接中的一个,并且成功了(请参阅更新)。