Freigeben über


The specified module could not be found. HRESULT : 0X800700E

This error message, by the look of it, is very straight forward. It clearly states that the application (irrespective of its type) failed due to a missing module. I had a similar feeling when I received this bright yellow message on my browser window the other day. Next obvious question: which module am I missing? Scan the whole error screen and you won’t find one. Let’s get down to business and find that out.

First a bit of background about the application as it holds the clue to the whole thing. I have a .NET 3.5 web application developed in C#. This referenced a managed C++ dll (ManagedWrapper.dll) which was a wrapper over an unmanaged C++ dll (UnmanagedTest.dll). The native dll had a single “Hello” method which returned “Hello World” string.

#include "StdAfx.h"

#include "TestObject.h"

TestObject::TestObject() {}

std::string TestObject::Hello()

{

return "Hello World";

}

I included a reference of ManagedWrapper.dll inside my web application. Copied UnmanagedTest.dll inside the bin directory of the web application. My intention was to call the Hello() method present within the native dll from my web application. To test whether the setup will work or not before any development inside the web application, I published the web application on IIS 6.0 and browsed to the default.aspx page from IE7. It failed with the above mentioned error message. Managed Exception :

                                 System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Partial Stack Trace of the failing thread:

[FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)]

System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0

System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +54

System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +211

System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +141

System.Reflection.Assembly.Load(String assemblyString) +25

System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +32

First I enabled fusion logging for ASP.NET and reproduced the issue. The logs were not able to point me to the failing module. Next I collected process monitor trace and root cause was in front of me:

w3wp.exe 2012 QueryOpen C:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\managedwrappersite\5bbb713b\7beac3fa\assembly\dl3\bfbeeb54\95e2dc78_66d5c801\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\system32\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\system\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\system32\inetsrv\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\system32\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\WINNT\system32\wbem\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\Program Files\Windows Imaging\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\Program Files\CA\SharedComponents\ScanEngine\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\Program Files\CA\eTrust Antivirus\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\Program Files\Microsoft Network Monitor 3\UnmanagedTest.dll NAME NOT FOUND

w3wp.exe 2012 QueryOpen C:\Program Files\Microsoft SQL Server\90\Tools\Binn\UnmanagedTest.dll NAME NOT FOUND

This shows that we are not failing to load ManagedWrapper.dll, but rather UnmanagedTest.dll. Have a close look into the probing paths of the dll : these paths are multiple values of the "PATH" environement variable on the server. Why does w3wp.exe look for a native dll in these paths instead of the application bin directory ? There is a reason for that as well. .NET Framework loads any dll present in the application bin folder as a managed dll. When we place an unmanged native dll in that place, it fails to load the dll and complains, just as it is doing in this scenario.

Resolution in this case will be to place the native dll in any of the probing paths specified in the above trace. We can also place the dll inside a custom folder and set its path to "PATH" environment variable at runtime. Next time you get this error message, make efficient use of the process monitor to catch the culprit.