dllimport failed to locate dll even though it is in the PATH

泪湿孤枕 提交于 2019-12-08 17:43:40

问题


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"


回答1:


"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.




回答2:


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




回答3:


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.




回答4:


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")].



来源:https://stackoverflow.com/questions/294080/dllimport-failed-to-locate-dll-even-though-it-is-in-the-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!