Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

Tags:

c++

c#

dll

pinvoke

People also ask

How do I fix Hresult 0x8007007E?

If you are receiving this error message at the startup of the computer, place the computer in clean boot state and check if any third-party program is causing this issue. Putting your system in clean boot state helps in identifying if any third party applications or startup items are causing the issue.

How do I fix system Dllnotfoundexception?

Simply, check pending updates, install them and/or restart Windows. After that frozen dll-s are freed and problems gone.

Could not load file or assembly DLL or one of its dependencies?

There are some workarounds for this issue: The dll file may not be in /bin folder. Just copy the dll file to /bin folder or set this preference Copy Local = True from Visual Studio. If the problem persists, check if the version of the assembly that is referenced is different than the version it is looking for.


From what I remember on Windows the search order for a dll is:

  1. Current Directory
  2. System folder, C:\windows\system32 or c:\windows\SysWOW64 (for 32-bit process on 64-bit box).
  3. Reading from the Path environment variable

In addition I'd check the dependencies of the DLL, the dependency walker provided with Visual Studio can help you out here, it can also be downloaded for free: http://www.dependencywalker.com


You can use the dumpbin tool to find out the required DLL dependencies:

dumpbin /DEPENDENTS my.dll

This will tell you which DLLs your DLL needs to load. Particularly look out for MSVCR*.dll. I have seen your error code occur when the correct Visual C++ Redistributable is not installed.

You can get the "Visual C++ Redistributable Packages for Visual Studio 2013" from the Microsoft website. It installs c:\windows\system32\MSVCR120.dll

In the file name, 120 = 12.0 = Visual Studio 2013.

Be careful that you have the right Visual Studio version (10.0 = VS 10, 11 = VS 2012, 12.0 = VS 2013...) right architecture (x64 or x86) for your DLL's target platform, and also you need to be careful around debug builds. The debug build of a DLL depends on MSVCR120d.dll which is a debug version of the library, which is installed with Visual Studio but not by the Redistributable Package.


The DLL has to be in the bin folder.

In Visual Studio, I add the dll to my project NOT in References, but "Add existing file". Then set the "Copy to Output Directory" Property for the dll to "Copy if newer".


This is a 'kludge' but you could at least use it to sanity-test: Try hard-coding the path to the DLL in your code

[DllImport(@"C:\\mycompany\\MyDLL.dll")]

Having said that; in my case running dumpbin /DEPENDENTS as suggested by @anthony-hayward, and copying over 32-bit versions of the DLLs listed there into my working directory solved this problem for me.

The message is just a bit misleading, becuase it isn't "my" dll that can't be loaded - it's the dependencies


Try to enter the full-path of the dll. If it doesn't work, try to copy the dll into the system32 folder.


Ensure that all dependencies of your own dll are present near the dll, or in System32.