Chain of dependency dll's not loading correctly.


I have 3 dlls A,B and C which I am trying to use from Unity but I am having an issue.

DLL A depends on B and B depends on C. The linking is run-time so A uses LoadLibrary for B and B does the same for C also the dlls use GetProcAddress to load specific functions from each dll.

When I test those 3 dll’s outside of Unity in a test project, everything seems to be working fine, whilst, when I import them to Unity the following happens:

First, Unity Loads A dll’s functions (e.g.)

[DllImport(dllName: "Story", CallingConvention = CallingConvention.Cdecl)] public static extern bool release();

Afterwards dll A tries to load dll’s B functions. While LoadLibrary(B) works on A (doesn’t return NULL), GetProcAddress(Bfunction) fails with error code 127 and thus A cannot load B functions from Unity.

As I mentioned earlier, the same setup works outside of Unity.

Any logic or reasoning behind this? Even better, any solutions to this matter?

Thanks in advance.

Hi Davelis4,

I have met same issues, that a native plugin DLL A, depends on DLL B and B depends on DLL C. Calling from Unity a DLL A function, which calls DLL B functions results in load failure. I have no source code of DLL B and C, they return me message “Library is not loaded” and an exception, so I assume the same issue as yours.

So far I have found two workarounds to get rid of this issue:

1, converting my DLL A to a executable application, and making another simpler DLL D to communicate between Unity and the executable. Due to my use case, this approach is acceptable. However this introduces more work and is less user friendly.

2, copying DLL B and DLLC to the “Editor” folder, where Unity.exe locates. Then calling DLL A has no problems. This approach is ugly for installation.

Hopefully, Unity could make our life easier.


PS: Using “Dependency Walker” with DLL A, I can see B and C are not on the list. I don’t know if this is why Unity can not load DLL B and DLL C. However, for dynamic loaded DLLs, how can we add them to the list ? If the 3rd party lib providers chose to dynamic load their dependencies, what else we could do?