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"
"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.
I'd suggest you to use FileMon (sysinternals.com) to check if your assumptions about the library location are right.
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.
I used const string lcms2Path = "C:\\lcms2.dll";
in my C# application for the longest time. But finally moved the DLL to the BIN folder and this works perfect [DllImport("lcms2.dll")]
.
© 2022 - 2024 — McMap. All rights reserved.