This is a .NET Core 2.0 console app that loads a C++ dll (DllImport). It "works on my machine" (windows 10, .NET Core 2.1.103) in all situations.
But when deployed in the staging env. it does not work if the exe is not executed from its current directory: if I run the executable from the parent directory, I get a System.DllNotFoundException: Unable to load DLL '***' : The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The problem is that this process is started this way and I have no other choices! (i.e. started from a parent process located in a parent folder)
I have tried to add a SetCurrentDirectory
+ SetDllDirectory
in the Main
method w/o any effects.
To summarize:
dotnet ***.dll
, it works from any directoryProcess.Start()
, it failsProcess.Start()
(which is the final use case)Last detail: the DllImport
is done in the context of an Activator.CreateInstance
(using Windsor)
A bit upset...
As Thomas suggested, it was related to the c++ runtime: it works in all situations if dependencies are all present in the current executable directory. A bit confusing as it worked in some cases without copying these dependencies (maybe a problem with the runtime installation)
User contributions licensed under CC BY-SA 3.0