从ASP.NET使用本机DLL时出现BadImageFormatException 我在ASP.NET应用程序中引用了一个托管C++项目,它使用了名为“LIbMMD .DLL”的本地DLL。如果我用visual studio运行ASP.NET应用程序,我会得到一个BadImageFormatException,它告诉我“模块应该包含程序集清单”(翻译自德语)

从ASP.NET使用本机DLL时出现BadImageFormatException 我在ASP.NET应用程序中引用了一个托管C++项目,它使用了名为“LIbMMD .DLL”的本地DLL。如果我用visual studio运行ASP.NET应用程序,我会得到一个BadImageFormatException,它告诉我“模块应该包含程序集清单”(翻译自德语),.net,asp.net,dll,interop,managed-c++,.net,Asp.net,Dll,Interop,Managed C++,将本机DLL包含到asp.net项目中的首选方式是什么?要在哪个目录中搜索文件?在路径“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\临时ASP.NET文件”中,似乎只有托管程序集,而不是本机DLL [FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)] System.Reflection.Ass

将本机DLL包含到asp.net项目中的首选方式是什么?要在哪个目录中搜索文件?在路径“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\临时ASP.NET文件”中,似乎只有托管程序集,而不是本机DLL

[FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +227
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +52
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8890751
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

确保ASP.NET应用程序的位(由IIS应用程序池设置)与本机dll的位匹配。例如,32位进程无法加载64位dll


附加:codymanix评论:


我的电脑是32位的,也都是DLL。当我将dll放入应用程序文件夹时,该库在windows窗体应用程序中工作。但是在ASP.NET中,我不知道将dll放在哪个文件夹中

将dll放入正确位置的最简单方法是让VS/ASP.NET通过以下任一方式进行:

  • 在项目参考上,将“复制本地”参数设置为true
  • 使用“无”生成操作将dll添加到项目中,并复制到目标文件夹
  • 将dll添加到项目的
    bin
    文件夹中

我将从最后一个选项开始,但还要检查以查看Windows尝试从何处加载dll(即加载路径中包含哪些web应用文件夹)。本机程序集和托管程序集之间的交互可能有点困难(由于加载程序搜索规则不同),ASP.NET随后会添加其自身的差异,这些差异在一定程度上适用于本机dll。

请确保ASP.NET应用程序的位(由IIS应用程序池设置)与本机dll的位匹配。例如,32位进程无法加载64位dll

[FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +227
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +52
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8890751
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

附加:codymanix评论:


我的电脑是32位的,也都是DLL。当我将dll放入应用程序文件夹时,该库在windows窗体应用程序中工作。但是在ASP.NET中,我不知道将dll放在哪个文件夹中

将dll放入正确位置的最简单方法是让VS/ASP.NET通过以下任一方式进行:

  • 在项目参考上,将“复制本地”参数设置为true
  • 使用“无”生成操作将dll添加到项目中,并复制到目标文件夹
  • 将dll添加到项目的
    bin
    文件夹中

我将从最后一个选项开始,但还要检查以查看Windows尝试从何处加载dll(即加载路径中包含哪些web应用文件夹)。本机程序集和托管程序集之间的交互可能有点困难(由于加载程序搜索规则不同),ASP.NET随后添加了自身的差异,这些差异在一定程度上适用于本机DLL。

我没有将windows%PATH%变量设置为包括本机DLL的路径,现在它可以工作了

[FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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: Das angegebene Modul wurde nicht gefunden. (Ausnahme von 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.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +227
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +52
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8890751
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

我还必须重新启动计算机才能运行。

我没有将windows%PATH%变量设置为包含本机DLL的路径,现在它可以工作了


我还必须重新启动计算机才能运行。

我的计算机是32位的,也都是DLL。当我将dll放入应用程序文件夹时,该库在windows窗体应用程序中工作。但是在ASP.NET中,我不知道将dll放在哪个文件夹中。@codymanix所以,是时候进行进程监视了。Win32试图从哪里加载本机dll?我的计算机是32位的,也都是dll。当我将dll放入应用程序文件夹时,该库在windows窗体应用程序中工作。但是在ASP.NET中,我不知道将dll放在哪个文件夹中。@codymanix所以,是时候进行进程监视了。Win32试图从何处加载本机dll?