ERROR_DLL_INIT_FAILED是什么意思?

发布于 2024-08-11 15:32:41 字数 190 浏览 6 评论 0原文

我在调用非托管程序集的托管 (C#) 应用程序中看到以下异常:

捕获:System.IO.FileLoadException '动态链接库 (DLL) 初始化例程失败。 (HRESULT 异常:0x8007045A)'

这个 HRESULT 是什么意思,我应该从哪里开始诊断?

I'm seeing the following exception in my managed (C#) app calling an unmanaged assembly:

Caught:System.IO.FileLoadException 'A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)'

What does this HRESULT mean, and where should I start in diagnosing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

向日葵 2024-08-18 15:32:41

在将 VS 2008 中的解决方案升级到目标运行时 v 4.0 的 .NET Framework v2.0 到 VS 2010 的项目后,我收到此错误。我得到的例外是:

无法加载文件或程序集“XYZ.dll”或其依赖项之一。动态链接库 (DLL) 初始化例程失败。 (HRESULT 异常:0x8007045A)":"XYZ.dll

通过将以下部分添加到设置为启动的项目的 App.config 文件中,已修复此问题:

<startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v2.0"/>
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

I was getting this error after upgrading a solution that was in VS 2008 and had projects targeting .NET framework v2.0 to VS 2010 with target runtime v 4.0. The exception I was getting was:

Could not load file or assembly 'XYZ.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)":"XYZ.dll

This was fixed by adding the following section to the App.config file of the project set as startup:

<startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v2.0"/>
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
妥活 2024-08-18 15:32:41

FileLoadException类

表示出现的错误
找到但无法找到程序集文件
已加载。

FileNotFoundException异常是
文件加载失败时抛出
因为无法定位。如果
文件已找到,但无法加载
由于权限不足,
抛出 SecurityException。

FileLoadException 有默认值
COR_E_FILELOAD 的 HRESULT,其中有
值 0x80131621,但这不是
唯一可能的 HRESULT。

如果你的代码没有
PathDiscovery权限,错误
此异常的消息可能仅
包含文件或目录名
而不是完全限定的路径。

直接引用自 MSDN:
链接文本

这通常只是一个简单的问题能够找到需要的库。

FileLoadException Class

Represents the error that occurs when
a Assembly file is found but cannot be
loaded.

The FileNotFoundException exception is
thrown when the file fails to load
because it cannot be located. If the
file is located, but cannot be loaded
due to insufficient permissions, a
SecurityException is thrown.

FileLoadException has the default
HRESULT of COR_E_FILELOAD, which has
the value 0x80131621, but this is not
the only possible HRESULT.

If your code does not have
PathDiscovery permission, the error
message for this exception may only
contain file or directory names
instead of fully qualified paths.

Quoted straight from MSDN:

link text

This is usually simply an issue of being able to find the required library.

阿楠 2024-08-18 15:32:41

或者,您尝试加载的 DLL 正在尝试加载缺失的 DLL,请检查 DLL 上的 DEPENDS.EXE

alternatively the DLL you try to load is trying to load a missing DLL, check with DEPENDS.EXE on the DLL.

逆光飞翔i 2024-08-18 15:32:41

我在应用程序关闭时收到此错误。它似乎是由控件中的垃圾收集“Finalize”方法引起的,该控件引用了多个 DLL 中的多个 COM+ 模块和其他非托管程序集。

我更正了控件的 Dispose 方法以调用 GC.SuppressFinalize,并在控件中设置了一个标志,以便托管代码部分仅运行一次。我还使用该控件修改了表单,以便它们始终显式关闭。

I was getting this error on application shutdown. It appeared to be provoked by the garbage collection "Finalize" method in a control which referenced several COM+ modules and other unmanaged assemblies in multiple DLLs.

I corrected the Dispose method of the control to call GC.SuppressFinalize and also set a flag in the control so that the managed code section only runs once. I also modified forms using the control so they were always explicitly closed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文