37

So I'm using an SDK for a hardware random number generator which provides a dll called PsyREG.dll for interacting with it, as well as some c# source for using the methods from the dll.

It has worked in the past, but somehow it has stopped working. My hands are a bit tied as I don't actually have access to the device in question at the moment, so I can't try a lot of things...

However, here's the weird thing. The dll is there, the same place it's always been. Ahd in fact File.Exists("PsyREG.dll") returns true, and I've double checked and that's the exact same way the provided c# source imports it, e.g. [DllImport("PsyREG.dll")].

Any ideas?

riQQ
  • 9,878
  • 7
  • 49
  • 66
Asmor
  • 5,043
  • 6
  • 32
  • 42
  • I had a similar issue with Google OrTools. I found a fix here: https://stackoverflow.com/a/63677664/1136310 – torbonde Jul 16 '21 at 21:47

5 Answers5

48

Probably this DLL has some dependencies that aren't registered or aren't in the same folder as your application.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Cleiton
  • 17,663
  • 13
  • 46
  • 59
  • Thanks, that was it. There were some other things that were needed, but for a few reasons I didn't think to check that (including the fact that it said it couldn't load PsyREG.dll, not a different file) – Asmor Aug 07 '09 at 19:53
  • 1
    Times like this are when I break out Reflector. It can show you the dependencies. In particular, it can show you which ones aren't found. – Brad Bruce Aug 07 '09 at 20:23
  • Really? Does Reflector find unmanaged dependencies? Where is that option? – erikkallen Aug 16 '10 at 09:32
  • 3
    I use DependancyWalker and, if that fails (i.e., if the DLL is being loaded dynamically), FileMon to simply watch where searches fail. – Ed S. Nov 12 '10 at 01:44
9

Open DLL on the problematic system in http://www.dependencywalker.com/

cbuteau
  • 736
  • 1
  • 7
  • 15
2

I ran into this problem and solved with the following:

There's a dependency on msvcr90.dll if you compile under /MD. Try compiling the code with /MT instead.

Project properties > C/C++ > Code Generation > Runtime Library: /MT

Slate
  • 3,189
  • 1
  • 31
  • 32
1

Perhaps you should check to see if you're expecting a specific product version of the dll, and make sure that the product versions still match up correctly.

Joseph
  • 25,330
  • 8
  • 76
  • 125
0

I was dealing with the same exception with regards to one of my DLL's (let's call it A). C# was crashing because it claimed it couldn't find this DLL (A) (while it was there in the same folder as the executable).

Turned out that the issue was caused by A having dependency on another DLL (call it B). B was not in the path so A couldn't load it when it needed it. Since B needed a whole bunch of other DLL's, the solution was to add B's directory to the PATH environment variable.

It's interesting how C# crashes with the error saying that A is not found when in fact B was not found...

Maghoumi
  • 3,295
  • 3
  • 33
  • 49
  • Can you explain the `the solution was to add B's directory to the path environment variable` part a little? I'm currently struggeling with almost the same problem, only difference is that my Dll wants some *.so files instead of other Dll's. – Stefan Nov 11 '16 at 10:13
  • @Stefan I believe in Linux terminal you would do `export PATH=$PATH:YOUR-SO-FILE-PATH` to add the directory `YOUR-SO-FILE-PATH` to your PATH environment variable. This way, when your `so` file needs to be loaded, the path specified by PATH will be searched to find that `so` file. – Maghoumi Nov 11 '16 at 16:56
  • Thanks, I've tried it that way but it didn't really work. I read somewhere else to move my dll into the `/usr/lib` directory (yes, it's indeed a linux system) and that worked without any further configuration – Stefan Nov 14 '16 at 10:43