在P / Invoking中找不到DLL时,如何获取有关缺少的特定非托管DLL的消息?

时间:2021-07-23 02:23:17

When you link to an unmanaged library (say 'A.dll') which in turn links to another library ('B.dll'), and B.dll is missing, you will get a run-time error message about failing to load 'B.dll'.

当您链接到一个非托管库(比如'A.dll')而后者链接到另一个库('B.dll'),并且缺少B.dll时,您将收到一条关于无法加载的运行时错误消息'B.DLL'。

But when you P/Invoke into 'A.dll' from managed code, you'll get a general exception of this form:

但是当您从托管代码P / Invoke到'A.dll'时,您将获得此表单的一般例外:

Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'A.dll': The specified module could not be found.

未处理的异常:System.DllNotFoundException:无法加载DLL“A.dll”:找不到指定的模块。

How can I get an error message that pinpoints the specific unmanaged dll file that failed to load, when p/invoking from managed code ?

当从托管代码调用时,如何获得一个错误消息,指出无法加载的特定非托管dll文件?

4 个解决方案

#1


4  

I don't think there's any specific API you can use to pinpoint why LoadLibrary (the underlying Win32 API) failed for 'A.dll'. I recommend the use of a tool like Dependency Walker to troubleshoot DLL loading errors.

我不认为您可以使用任何特定的API来确定为什么LoadLibrary(底层的Win32 API)因'A.dll'而失败。我建议使用像Dependency Walker这样的工具来解决DLL加载错误。

#2


0  

I'm not sure how you can get this in the form of an exception. When I run into this problem I usually try and open the DLL with depends.exe. It's pretty good and reporting missing dependencies that exist if the DLL is simply loaded from it's current location.

我不知道你怎么能以异常的形式得到它。当我遇到这个问题时,我通常会尝试用depends.exe打开DLL。它非常好,如果简单地从它的当前位置加载DLL,则会报告缺少的依赖项。

#3


0  

You won't be able to get an answer from the exception, but you can do it (with a lot of work) through Process Monitor. This article discusses how and also includes a tool to scan Process Monitor logs to find the specific problem.

您将无法从异常中获得答案,但您可以通过Process Monitor完成(通过大量工作)。本文讨论如何以及还包括扫描Process Monitor日志以查找特定问题的工具。

http://tech.blinemedical.com/debug-could-not-load-file-or-assembly-or-one-of-its-dependencies/

#4


0  

The Fusion Log Viewer is a good tool to debug assembly loading problems in .NET apps.

Fusion Log Viewer是调试.NET应用程序中的程序集加载问题的好工具。

For identifying general file-load problems, you can use Process Monitor.

要识别常规文件加载问题,可以使用Process Monitor。

#1


4  

I don't think there's any specific API you can use to pinpoint why LoadLibrary (the underlying Win32 API) failed for 'A.dll'. I recommend the use of a tool like Dependency Walker to troubleshoot DLL loading errors.

我不认为您可以使用任何特定的API来确定为什么LoadLibrary(底层的Win32 API)因'A.dll'而失败。我建议使用像Dependency Walker这样的工具来解决DLL加载错误。

#2


0  

I'm not sure how you can get this in the form of an exception. When I run into this problem I usually try and open the DLL with depends.exe. It's pretty good and reporting missing dependencies that exist if the DLL is simply loaded from it's current location.

我不知道你怎么能以异常的形式得到它。当我遇到这个问题时,我通常会尝试用depends.exe打开DLL。它非常好,如果简单地从它的当前位置加载DLL,则会报告缺少的依赖项。

#3


0  

You won't be able to get an answer from the exception, but you can do it (with a lot of work) through Process Monitor. This article discusses how and also includes a tool to scan Process Monitor logs to find the specific problem.

您将无法从异常中获得答案,但您可以通过Process Monitor完成(通过大量工作)。本文讨论如何以及还包括扫描Process Monitor日志以查找特定问题的工具。

http://tech.blinemedical.com/debug-could-not-load-file-or-assembly-or-one-of-its-dependencies/

#4


0  

The Fusion Log Viewer is a good tool to debug assembly loading problems in .NET apps.

Fusion Log Viewer是调试.NET应用程序中的程序集加载问题的好工具。

For identifying general file-load problems, you can use Process Monitor.

要识别常规文件加载问题,可以使用Process Monitor。