Click here to Skip to main content
13,050,237 members (97,568 online)
Click here to Skip to main content
Add your own
alternative version

Stats

60.2K views
3 bookmarked
Posted 29 Feb 2012

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

, 2 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to fix this DLL importing error

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 are 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)

Share

About the Author

bovykinmaxim
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionThis solves my problem.. Pin
rosdi5-Jul-17 15:11
memberrosdi5-Jul-17 15:11 
QuestionYou guys are awsome! Pin
Uricano19-Jul-16 22:33
memberUricano19-Jul-16 22:33 
GeneralMy vote of 5 Pin
marcus187721-Jul-15 15:38
membermarcus187721-Jul-15 15:38 
AnswerGreat article Pin
abhishe Tandonk4-Nov-14 1:48
memberabhishe Tandonk4-Nov-14 1:48 
QuestionThank you So Much Pin
Member 1030326128-Oct-13 0:27
memberMember 1030326128-Oct-13 0:27 
AnswerThanks thanks thanks Pin
Member 953255521-Oct-12 0:20
memberMember 953255521-Oct-12 0:20 
GeneralMy vote of 5 Pin
RusselSSC4-Mar-12 3:12
memberRusselSSC4-Mar-12 3:12 
GeneralRe: My vote of 5 Pin
bovykinmaxim19-Mar-12 10:51
memberbovykinmaxim19-Mar-12 10:51 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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