Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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# Assembly.Load和Environment.CurrentDirectory_C#_.net_Assemblies - Fatal编程技术网

C# Assembly.Load和Environment.CurrentDirectory

C# Assembly.Load和Environment.CurrentDirectory,c#,.net,assemblies,C#,.net,Assemblies,我意识到这里有一个相关的线索: 但我正在修改一些东西,这并不完全适用 string path = Path.GetDirectoryName( pathOfAssembly ); Environment.CurrentDirectory = path; Assembly.Load(Path.GetFileNameWithoutExtension(pastOfAssembly)); 你真的有什么理由这样做吗?仅仅使用以下选项是否更有意义: Assembly.LoadFile(pathOfAs

我意识到这里有一个相关的线索:

但我正在修改一些东西,这并不完全适用

string path = Path.GetDirectoryName( pathOfAssembly ); 
Environment.CurrentDirectory = path;
Assembly.Load(Path.GetFileNameWithoutExtension(pastOfAssembly));
你真的有什么理由这样做吗?仅仅使用以下选项是否更有意义:

Assembly.LoadFile(pathOfAssembly);
任何洞察都将不胜感激。

看起来像是“冗余部门”

比需要的代码多得多。少就是多


编辑:仔细想想,可能是您正在加载的程序集的依赖项位于其自己的文件夹中,使用第一个程序集可能需要这些依赖项

在开发windows服务时,这是必要的。服务的工作目录默认为%WinDir%,因此,如果要从服务exe所在的目录加载程序集,可以这样做