In our ASP.NET Core web api, we are attempting to load unmanaged C++ code from a DLL that we included in our published folder.
This fails upon calling the endpoint that loads the DLL. The exception is as follows:
DllNotFoundException: Unable to load DLL 'libespeak-ng' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
It should be noted that this DLL loads and functions fine when the app is run through Visual Studio. Running the app in Kestrel with the dotnet command also works properly, on the same server. It is only inside of IIS that the app fails to load this DLL.
We have made sure the IIS user (as well as the default app pool) has permission to read and execute the DLL. We've tried placing the DLL in the app bin folder, in System32, in SysWOW64, and in the various inetsrv directories. None of this has resolved the issue.
Looking at ProcMon, it seems like IIS does not even attempt to load the DLL. Dependency Walker doesn't reveal any missing dependencies that aren't also missing when running it with Kestrel on any machine.
After many hours of struggling, and attempting the solutions commented by other users, we finally figured out the issue.
The DLL was trying to access some Windows APIs that did not exist in Windows Server 2012 R2, apparently. Once we updated the server to the latest windows server version, everything worked without issue.
User contributions licensed under CC BY-SA 3.0