I dynamically load the .NET assembly, which depends on several bundles of native .dlls located in different folders. But Windows only finds these DLLs if their folders are in the PATH environment variable when my application starts.
I would like to change my PATH variable from my program so that I can find the libraries I need. According to
MSDN,
"the search order is as follows: ... Directories listed in the PATH environment variable."
What instance of the PATH environment variable is used?
Each process has an instance.
I tried Environment.SetEnvironmentVariable("PATH", ...), but that didn't help. I also tried
SetDefaultDllDirectories ()
along with
AddDllDirectory ()
but that didn't matter either.
The symptom is that when it %PATH%contains the necessary folders when starting my .exe (from the CMD prompt it is a console application), ProcessMonitor shows that the native .dlls are examined in all PATH folders and are ultimately located.
But when it %PATH%does not contain the necessary folders at startup, the local .dlls are examined in the .exe folder and only in SYSTEM32 (although it %PATH%contains much more), regardless of the above calls to SetEnvironmentVariable () / SetDefaultDllDirectories () / AddDllDirectory ().
? ? PATH ?
. AppDomain.AssemblyResolve , , native.dlls
.dlls.