What does ERROR_DLL_INIT_FAILED mean?

3

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?

exception
hresult
asked on Stack Overflow Nov 17, 2009 by Justin

4 Answers

3

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.

answered on Stack Overflow Nov 17, 2009 by Egor
3

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>
answered on Stack Overflow Sep 19, 2011 by Sudhanshu Mishra • edited Aug 17, 2012 by Uwe Keim
2

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

answered on Stack Overflow Nov 17, 2009 by AndersK
0

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.

answered on Stack Overflow Sep 24, 2020 by Mike Pettigrew

User contributions licensed under CC BY-SA 3.0