views:

2933

answers:

3

I use [Dllimport("DllName.dll")] where I'm sure a path to my dll exists in the process PATH environment variable, and still I get "DllName.dll could not be found"

A: 

I'd suggest you to use FileMon (sysinternals.com) to check if your assumptions about the library location are right.

+1  A: 

DllImport does not consult the PATH environment variable when loading DLL's. I am fairly certain that DllImport follows the standard rules for loading a native DLL in a native program when the DLL is referenced by name. Here is an article which details those rules

http://msdn.microsoft.com/en-us/library/ms682586.aspx

I've found the simplest way to load the DLL is just to put it in the same location as the program I am executing.

JaredPar
+3  A: 

"DllName.dll could not be found" could also mean that DllImport has not found one of DllName.dll dependencies.

Grab Dependecy Walker to check which dependecy you are missing.

Arborend