Click here to Skip to main content
Click here to Skip to main content

DLL Dependency Viewer or How To Fix Exception: “Unable to load DLL “…” The specified module could not be found. (Exception from HRESULT: 0x8007007E)”

By , 2 Mar 2012
 

If you are involved in projects where software and hardware come together, you have probably already faced the exception I’m writing in this post about.

In our company, one of my responsibilities is to develop a communication layer between our software and compatible with it hardware. Without digging into details, I can just say that mostly it is a real *.DLL hell… What I have to work with is just a piece of hardware and a provided *.DLL to call hardware commands. Usually I don’t know what is inside this *.DLL. It’s a black box. I know just external interfaces.

I love to use the .NET platform for such kind of cases because of an awesome .NET Interoperability Platform. I can always keep my communications without any changes (Sockets, WCF, LINQ, etc.) and use imports from *.DLL:

using namespace System::Runtime::InteropServices;

[DllImport("SOME_HARDWARE_DLL.dll")]
static void SOME_DLL_METHOD();

One of the problems you can face there is that you never know what is going on inside the *.DLL. Once I got this type of exception:

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

I thought I’m crazy, because the *.DLL was in the correct place. I did everything I thought I could: placing the *.DLL near the executable, placing it inside Visual Studio Solution folder, inside {WindowsDir}\System directory (System32, SysWOW64), everywhere I could. I set the PATH to every place. Nothing helped. I spent almost 5 hours trying to find any error inside the code. But then I found an extremely helpful utility – Dependency Walker.

And it happened that inside this *.DLL was a call to another *.DLL which was missing on my machine!

image

It turns out (unfortunately) that in all situations like that one – one *.DLL is dependent on another – the .NET Interop will always give you the same: “Unable to load DLL: The specified module could not be found. (Exception from HRESULT: 0x8007007E)”. Once I installed the required driver (yet another one for that case) everything immediately became just fine.

Conclusion: check for dependencies if you working with third-party “black-box” *.DLL.

Thanks and happy DllImporting. Max.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

bovykinmaxim
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
AnswerThanks thanks thanksmemberMember 953255521 Oct '12 - 0:20 
GeneralMy vote of 5memberRusselSSC4 Mar '12 - 3:12 
GeneralRe: My vote of 5memberbovykinmaxim19 Mar '12 - 10:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130513.1 | Last Updated 2 Mar 2012
Article Copyright 2012 by bovykinmaxim
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid