2010-09-16 50 views
1

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

将本地dll包含到asp.net项目中的首选方式是什么?在哪个目录中搜索?在“C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files”路径中,似乎只有托管程序集,而不是本机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 

回答

0

我没有设置windows%PATH%-variable来包含我的本机DLL的路径,现在它可以工作。

我也必须重新启动我的机器才能运行。

1

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


附加:codymanix评论:

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

得到一个dll到正确的位置,最简单的办法就是让VS/ASP.NET做到这一点有两种方法:

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

我将与最后一个选项启动,也与Process Monitor检查,看看Windows试图加载从(即什么是Web应用程序文件夹都包含在负载路径)的DLL。原生程序和托管程序集之间的交互可能有点困难(由于不同的加载程序搜索规则),ASP.NET会添加自己的差异,适用于本地dll的程度。

+0

我的电脑是32位,也都是Dll。当我将dll放入应用程序文件夹时,该库在Windows窗体应用程序中工作。但在ASP.NET中,我不知道在哪个文件夹中放置该DLL。 – codymanix 2010-09-16 10:46:33

+0

我尝试了所有这些,但没有任何帮助 – codymanix 2010-09-20 11:29:15

+0

@codymanix so,Process Monitor的时间。 Win32从哪里加载本地dll? – Richard 2010-09-20 12:15:34

相关问题