Mat*_*ias 9 c++ asp.net dll c++-cli filenotfoundexception
我必须在我的一个ASP.NET项目中包含一个(托管的)C++/CLI组件,它自己引用一些其他(非托管)C++ DLL.应该没问题 - .NET 3.5很高兴在编译项目时,一切看起来都很好.C++/CLI组件和其他C++ DLL由另一个部门编译为Visual Studio 2005中带有"Any CPU"的Release版本.安装了VC++ 2005 Redistributable软件包.当我在普通的.NET控制台应用程序中运行它时,相同的代码可以正常工作.
现在,虽然此代码在控制台应用程序中工作,但它没有被ASP.NET正确托管 - 它导致初始页面加载时出错(甚至在进入Global.asax之前).为了测试和调试,我使用了两种机器配置:
在两台计算机上,当我启动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
Run Code Online (Sandbox Code Playgroud)
现在,这是不可思议......这并不是说对任何事情有什么组件丢失,甚至Fuslogvw.exe或sxstrace.exe没有任何记录.此外,似乎错误取决于C++/CLI程序集或非托管C++ DLL.如果我从我的ASP.NET项目和代码中删除C++/CLI程序集引用,它可以正常工作.现在因为C++/CLI程序集依赖于ASP.NET项目中未引用的本机C++ DLL,我将所有依赖的C++ DLL复制到ASP.NET项目输出文件夹的"bin"文件夹中(与工作程序控制台相同)应用).虽然每个C++的东西都是在发布模式下编译的,但是安装了正确的VC++ Redist Package后,应该存在所有依赖项.当然我知道有一个FileNotFoundException,但我无法弄清楚缺少什么......
如上所述:用于访问C++/CLI组件的相同代码在两台测试PC上的.NET 3.5控制台应用程序中工作(我部署了相同的依赖项),并且在ASP中部署到输出文件夹中的相同依赖C++ DLL. NET我得到了上面的错误.
有什么建议我可以摆脱这个问题或如何进一步追踪它?
(当然我搜索了StackOverflow和Google的问题,例如我找到了这些链接,但他们没有帮助:
- "运行C#ASP.NET web服务时引用C++ dll时无法找到指定的模块"错误
- 访问x86 COM从64位.NET
- ASP.NET应用程序在32位环境中的64位环境中工作不开发
- 模块未发现异常从.NET 2.0的Web服务在Windows Server 2008 R2)
小智 5
ProcMon救了我.
路径也是我的问题.似乎IIS正在C:\ Windows\System32\inetsrv文件夹中创建每个托管dll的卷影副本.但这不是非托管代码的情况.当必须加载非托管dll时,它会搜索环境路径,而不是IIS中应用程序的bin目录.
非常感谢Aristos !!
您的代码达到了_nLoad,这很好,因为已经通过了所有加载检查并移动到核心以实际加载 dll,但它失败了。
首先Dependency Walker
从http://www.dependencywalker.com/下载并在 dll 上使用它来找出该 dll 需要运行的其他资源。我怀疑无法加载其他一些dll文件。
另外,这个 dll 可能会搜索其他无法找到的文件,这就是无法加载的原因。第二种方法是使用File Monitor、 或Process Monitor来自 sysinternals 来查找加载失败的内容。
http://technet.microsoft.com/en-us/sysinternals
http://technet.microsoft.com/en-us/sysinternals/bb896645
| 归档时间: |
|
| 查看次数: |
2890 次 |
| 最近记录: |