PInvoke - Specified module could not be found. How to check for missing dependencies?

0

I have a .Net application which relies on an unmanaged dll called Procarper.dll. When I run this on my personal machine, the application runs perfectly fine.

When I copy this same application to my server (Windows 2008) and attempt to run it there it fails with the below error message.

The reason I'm testing with an actual application is because this initially was failing in my WCF service.

System.DllNotFoundException: Unable to load DLL 'C:\Warper\Procarper.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

The PInvoke signature looks like this (I'm hardcoding the path as a test...it would typically just be relative):

[DllImport(@"C:\Warper\Procarper.dll", EntryPoint = "CreateProcr", CallingConvention = CallingConvention.Cdecl)]
        private static extern int CreateProcr(int width, int height, int scanWidth, int bpp, IntPtr rawData);

I am looking at dependencywalker but honest I don't know how to really judge what it's telling me it has been a very long time since I've had to work with C++.

Based on the above information can anyone help me determine what is failing?

I'd be happy to provide more information just please ask and I'll supply it.

c#
c++
.net
dll
pinvoke
asked on Stack Overflow Sep 13, 2014 by tronious • edited Sep 4, 2018 by Uwe Keim

1 Answer

2

So in case anyone runs into something similar, hopefully my experience can help.

Here's how I solved the problem. (HINT: Install DependencyWalker on the machine that's giving you the problem and walk the .dll you're having problems with. DependencyWalker will show the missing dependencies or target CPU mismatches in Red).

  1. I knew the application ran on Computer A. I knew the same application failed on Computer B.

  2. The error message was "specified module could not be found". I was focused on the actual .dll.

  3. In REALITY, the error was not related to the fact that it couldn't find the .dll. Rather, it was the fact that it couldn't find a dependency that the Procwarper.dll relied in. In this case namely:

MSVCP120D.DLL and MSVCR120D.DLL

  1. In order to determine #3, I used dependencywalker (www.dependencywalker.com). Since I knew the .dll was 32-bit, I installed the 32-bit version of dependencywalker.

  2. I loaded Procwarper.dll into dependencywalker on Computer A (the one where the application works). Dependencywalker showed no problems.

  3. I loaded dependencywalker onto Computer B (where the application fails). DependencyWalker showed two missing dependencies (the two shown above).

  4. I copied those from windows\System32 folder of Computer A to Computer B APP FOLDER

  5. I reran dependencywalker. It now showed now missing dependencies, but I still had an Error because the .dll's in System32 are 64-bit.

  6. I did a quick google and found out that the SysWow64 folder holds the 32-bit versions of those System32 dll's.

  7. I copied those two up to Computer B and everything worked. Copy to APP FOLDER

Unbelievable. Now I know why they refer to it as ".dll hell".

Hopefully this helps someone.

answered on Stack Overflow Sep 13, 2014 by tronious • edited Sep 13, 2014 by tronious

User contributions licensed under CC BY-SA 3.0