I am trying to consume a win32 DLL in a .net MVC app. However I keep getting the following error Unable to load DLL 'experiment_dll.dll': The specified module could not be found
I have used Process Monitor to capture file system activity when the code trying to load the DLL executes. It shows that the DLL can be seen and most of the file system operations are a success.
Two full size screen captures of file system activity -
As you can see one of the results of one of the operations is FILE LOCKED WITH ONLY READERS
. Could this be the reason why the DLL is failing to load and why the error message is saying that the DLL could not be found?
UPDATE:
I have found this forum thread that says that this result is actually a success and so shouldn't be the problem - http://forum.sysinternals.com/topic21378.html
If this is a permissions issue, how can it be fixed? I have already given the App Pool full control on the DLL file and on the Bin and Root folders.
I have tried creating a test MVC app and a test DLL (which just exports a single function that takes a bool and returns the same bool. I have tried making the test MVC x86 and DLL win32 (both release builds) and setting the Enable 32-Bit Applications
App Pool setting to true. I have also tried making the test MVC x64 and the DLL x64 (both release builds) and setting the Enable 32-Bit Applications
App Pool setting to false. I have also tried Any Cpu
configurations. All produce the same error and all produce the same file system activity as shown in the screen captures.
I am experiencing this problem when publishing to IIS 8.5, Windows Server 2012 R2 running on Azure Virtual Machine.
The DLL loads without issue when publishing to a free mywebsite.azurewebsites.net
or when running on my development machine.
It turns out, after checking the DLL with Dependency Walker on the server, that a dependency which was installed with Visual Studio was not available on the server,
MSVCR120.dll
. Initially I thought that because I had not given the DLL any dependencies myself that there would not be any dependencies that could be missing. So I overlooked it. Bad decision!