asp.net - ASP.NET 中的 C++/CLI 组件出现 "module could not be found"错误

标签 asp.net c++ dll c++-cli filenotfoundexception

我必须在我的一个 ASP.NET 项目中包含一个(托管的)C++/CLI 组件,它自身引用了一些其他(非托管的)C++ DLL。应该没问题 - .NET 3.5 在编译项目时很高兴,一切似乎都很好。 C++/CLI 组件和其他 C++ DLL 由另一个部门在 Visual Studio 2005 中使用“任何 CPU”编译为发布版本。安装了 VC++ 2005 Redistributable 包。当我在普通的 .NET 控制台应用程序中运行相同的代码时,它可以毫无问题地工作。

现在虽然此代码在控制台应用程序中运行,但它没有被 ASP.NET 正确托管 - 它会导致初始页面加载错误(甚至在进入 Global.asax 之前)。 为了测试和调试,我使用了两种机器配置:

  1. 本地开发 PC:Windows XP,32 位,VC++ 2005 Redist 包,Visual Studio 2010,ASP.NET 3.5,编译“任何 CPU”,在 Web 开发服务器 (Cassini) 中托管
  2. 测试服务器(目标机器):Windows 7、64 位、VC++ 2005 Redist 程序包、在 IIS 7 中托管、AppPool 已设置“启用 32 位应用程序”

当我启动 ASP.NET 应用程序时,在两台机器上都出现了以下相同的错误:

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

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[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) +43
 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
 System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
 System.Reflection.Assembly.Load(String assemblyString) +28
 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)]
 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
 System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
 System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
 System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +86
 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +126
 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +62
 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
 System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

现在这很奇怪......它没有说明什么程序集丢失,甚至 Fuslogvw.exesxstrace.exe 没有记录任何东西。 当然,错误似乎取决于 C++/CLI 程序集或非托管 C++ DLL。如果我从我的 ASP.NET 项目和代码中删除 C++/CLI 程序集引用,它就可以正常工作。现在因为 C++/CLI 程序集依赖于 ASP.NET 项目中未引用的 native C++ DLL,我将所有依赖的 C++ DLL 复制到 ASP.NET 项目输出文件夹的“bin”文件夹(与 workgin 控制台相同应用)。虽然每个 C++ 东西都已在 Release模式下编译,并安装了正确的 VC++ Redist 包,但应该有所有依赖项。我当然知道有一个 FileNotFoundException,但我不知道缺少什么...

如前所述:用于访问 C++/CLI 组件的相同代码在两台测试 PC 上的 .NET 3.5 控制台应用程序中工作(我在其中部署了相同的依赖项),并将相同的相关 C++ DLL 部署到输出文件夹中,只是在 ASP.NET 中出现上述错误。

关于如何解决问题或如何进一步跟踪它有什么建议吗?

(当然,我在 StackOverflow 和 Google 上搜索了这个问题,例如,我找到了这些链接,但它们没有帮助:
- "The specified module could not be found" error when running C# ASP.NET web service referring C++ dll
- Access x86 COM from x64 .NET
- ASP.NET application developed in 32 bit environment not working in 64 bit environment
- Module Not Found Exception From .NET 2.0 Web Service On Windows Server 2008 R2 )

最佳答案

ProcMon 救了我。

路径也是我的问题。似乎 IIS 正在 C:\Windows\System32\inetsrv 文件夹中创建每个托管 dll 的卷影拷贝。但这不是非托管代码的情况。当它必须加载非托管 dll 时,它会搜索环境路径而不是 IIS 中应用程序的 bin 目录。

非常感谢阿里斯托斯!!

关于asp.net - ASP.NET 中的 C++/CLI 组件出现 "module could not be found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9208003/

相关文章:

vb.net - 如何找出非托管 dll 的正确参数结构?

java - 向客户端提供/导出可执行文件

c# - 在 ASP.NET 中使用 HTTP 处理程序生成要在电子邮件中显示的图像

c++ - union Initializer "error: expected primary-expression before ‘.’ token ”

c++ - QByteArray 转换和指针转换

C++ 链表迭代成员访问运算符

c# - Unity - 如何使用 c++ dll?

asp.net - IE 10 不显示文本框宽度和高度

c# - 从 javascript 调用 ASP 生成的按钮单击

c# - 从 asp.net 中的表单插入到表中