2

I'm getting a System.DllNotFoundException for a .dll which is in the same folder as the executable whenever my application attempts to use a function which exists in the DLL. The weird thing is that it is only occurring on one user's PC; it works fine on my dev PC and it works fine on one non-dev PC that I tried it on. Also, there are other DLLs in the folder which are being found and used correctly. The DLL in question is a native library which is referenced by my application via another DLL which is a c# wrapper for the native library.

My initial instinct is that there must be some other library being referenced by this DLL which doesn't exist on the problematic PC, but I cannot imagine what library this PC could be missing that the other non-dev PC has.

So my questions are this: is there a way to determine the dependencies of a given DLL file? Keep in mind that the DLL in question is a native library (i.e. not managed code), and I do not have access to it's source code. And if it turns out no dependency is missing, what else might cause such an issue?

jjoelson
  • 5,771
  • 5
  • 31
  • 51
  • 1
    Any chance this native library that you are trying to load is compiled against a CPU architecture (for example x86) different than the one of the hosting process (for example x64)? – Darin Dimitrov Sep 12 '11 at 20:20
  • @Darin Dimitrov: That usually leads to a BadImageFormatException. – dtb Sep 12 '11 at 20:22
  • @dtb, that's true, it was just the first thing that came to mind. – Darin Dimitrov Sep 12 '11 at 20:23
  • The architectures match up. The problematic PC has the same hardware and OS specs as my dev PC. – jjoelson Sep 12 '11 at 20:27
  • 1
    Troubleshoot this with SysInternals' ProcMon. You'll see the program searching for the missing DLL in the directories that are on the PATH. A missing runtime support library that needs to go in the side-by-side cache is typical btw. – Hans Passant Sep 12 '11 at 21:09

2 Answers2

4

For unmanaged dlls you can use Dependency Walker to find dependencies.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
  • Thanks, I found a Dependency Walker mirror. It lists only MSVCP100.DLL, MSVCR100.DLL, and KERNEL32.DLL as dependencies for this library. As far as I know, these DLLs should be in the c:\Windows\System32 directory. I'll check to make sure the problematic PC has these DLLs. – jjoelson Sep 12 '11 at 20:36
  • 1
    I think MSVCR is the Visual C++ runtime and AFAIK it is not included with windows. At least he newer versions of it on older versions of windows. It's installed with many programs and thus often but not always present. No idea about MSVCP, but I imagine the situation might be similar. – CodesInChaos Sep 12 '11 at 20:45
  • That sounds like it might be the culprit. I can't check the problem PC until the user leaves for the day, but if this is the issue then I imagine just copying those two DLLs won't be sufficient. Correct me if I'm wrong, but I'll probably have to install something like this: http://www.microsoft.com/download/en/details.aspx?id=14632 – jjoelson Sep 12 '11 at 21:11
  • I usually side stepped the problem my linking statically with the runtime, but you can't do that since you don't have the source. If I recall correctly copying the files directly works, but I don't know under which circumstances you may distribute them legally. – CodesInChaos Sep 12 '11 at 21:18
  • Dependency Walker is great! – M22an Oct 19 '16 at 06:02
0

I would suggest using ILSpy to open the dll and view its dependencies first.

James
  • 539
  • 2
  • 6