从路径加载DLL在指定SetDllDirectory会在c# [英] Loading dlls from path specified in SetdllDirectory in c#
问题描述
我在dotnet.I是新有,通过使用加载 C
DLL 的DllImport
A DOTNET DLL。我希望把所有的DLL是从应用程序的位置不同势一个文件夹中。我不想修改环境变量。所以我用 SetDllDirectory会
API,并通过 Assembly.Loadfrom载入我的C#程序集(..)
。我检查了 SetDllDirectory会
通过验证 GetDllDirectory的价值做工精细(..)
。但它既不是加载C#DLL也不c从该文件夹中的DLL。我能够通过specyfing在 Assembly.Loadfrom
的路径来加载 C#
DLL。但无法加载C DLL。
I am new in dotnet.I have a dotnet dll that loads a c
dll by using DllImport
. I want to place all the dlls in a folder which is diffrent from the location of application. I dont want to modify environmental variables. So i used setdlldirectory
API and load my c# assembly through Assembly.Loadfrom(..)
. I checked that SetdllDirectory
is working fine by verifying the value of GetDllDirectory(..)
. But it is neither loading C# dll nor c dll from that folder. I am able to load C#
dll by specyfing the path in Assembly.Loadfrom
. But not able to load c dll.
在此先感谢!
推荐答案
我建议添加目录路径PATH环境变量在运行时,使用以下code:
I'd suggest adding the directory path to PATH env variable in runtime, using the following code:
var dllDirectory = @"C:/some/path";
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dllDirectory);
这样,变化只影响到正在运行的进程,退出时被丢弃。
That way, the change is only affecting the running process and is discarded when it exits.
这篇关于从路径加载DLL在指定SetDllDirectory会在c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!