What does ERROR_DLL_INIT_FAILED mean?

Justin picture Justin · Nov 17, 2009 · Viewed 11.9k times · Source

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?

Answer

Egor picture Egor · Nov 17, 2009

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.