C# Unable to load DLL When In Subdirectory

277 views Asked by At

I have a third party C# library my code references, let's call it a.dll, this library in turn depends on an unmanaged C dll, cApi.dll. The C library comes in x86 and x64, and I have them stored in respective folders and Copy always set. When I call the init method of a.dll from my code I get the error message Unable to load DLL 'cApi.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E). My code has a reference to a.dll, so my bin when debugging looks like:

bin/debug/
---a.dll
---x86/
------cApi.dll
---x64/
------cApi.dll

When I inspect the code that is in a.dll it uses DllImport attribute to make calls to cApi.dll. If I copy either of the cApi.dll's to the same directory a.dll is output to, I will not get the error. Does DllImport not search the sub directories in the bin? How can I resolve this issue, should I add build logic to copy the correct cApi.dll to the same dir as a.dll, or is there a way to get it to work with the current structure?

EDIT I have a <probing> element in my config file: <probing privatePath="x86;x64"/>

0

There are 0 answers