2014-07-22 56 views
0

我打的异常:调试无法加载DLL'MyDll.dll':无法找到指定的模块。 (异常来自HRESULT:0x8007007E)

Unable to load DLL 'MyDll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) 

由于答案Unable to load DLL (Module could not be found HRESULT: 0x8007007E)表明,我们要保持非托管的DLL在当前目录,连同所有托管的DLL(和它在那儿)。为了调试目的,我怎样才能打印将用于加载dll的当前目录?是Directory.GetCurrentDirectory()

+0

Dll文件夹的搜索顺序在这里描述:http://stackoverflow.com/questions/268627/where-does-dllimport-look-for-unmanaged-dlls 你也可以显式设置搜索目录,如下所述:http ://stackoverflow.com/questions/2864673/specify-the-search-path-for-dllimport-in-net –

+0

当前目录不是特别相关。你没有显示任何代码或给我们足够的细节。 –

+0

@DavidHeffernan,当前目录怎么不相关?它应该是第二个地方寻找DLL ... – Grzenio

回答

0

您可以使用Environment.CurrentDirectory获取您的应用程序的当前工作目录。这应该让你想要你想要的。

Assembly.GetExecutingAssembly()。Location将返回包含当前正在执行的可执行文件或DLL的目录。

CurrentDirectory可以被FileDialogs和其他类改变。因此,它可能与包含应用程序入口点的目录不同。

+0

此外,如果将DLL加载到.NET中,.NET可以在GAC(全局程序集缓存)中找到DLL。 –

相关问题