【问题标题】:Web.config system.webserver errorsWeb.config system.webserver 错误
【发布时间】:2015-02-05 21:03:51
【问题描述】:

我正在尝试将我的 C# ASP.Net 应用程序部署到我的托管站点。问题是我有 2 个应用程序使用的 C++ dll,但是对于共享主机,它们不能位于 bin 文件夹中。它们已在项目中的一个名为“bin_native”的文件夹中被引用。该应用程序在我的机器上运行,使用 web.config 的运行时部分中的探测 privatePath 和 Default.aspx 文件顶部的 Assembly 指令。但它不会像那样在服务器上运行。网站加载时解析default.aspx时找不到dll,该文件顶部的2个Assembly指令出错。

所以我试图在 web.config 的 system.webserver 部分中添加对 dll 的引用。该网站的支持人员说,如果我能做到这一点,也许该应用程序可以使用位于我的网站 wwwroot 文件夹(ASP.Net bin 文件夹所在的位置)的父目录中的单独 bin 文件夹。这样应用就可以找到 dll。

但我无法正确无误地修复 system.webserver 部分。当我在我的机器上测试时,我收到以下错误:

Server Error in '/' Application.

Could not load file or assembly 'find_duplicates, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'find_duplicates, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

以下是我目前对项目所做的更改:

默认.aspx:

<%@ Assembly Name="find_duplicates" %>
<%@ Assembly Name="trim_combos" %>

Web.config:

 <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">

     <add name="find_duplicates" type="find_dups.find_duplicates, find_duplicates,Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248"  />

      <add name="trim_combos" type="trim_coms.trim_combos, trim_combos, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248"  />

     </modules>

    <validation validateIntegratedModeConfiguration="false" />

  </system.webServer>

 <runtime>  

    <dependentAssembly>

       <assemblyIdentity name="find_dups.find_duplicates.find_duplicates" publicKeyToken="e02ee5289fcc8248" culture="neutral" />

    </dependentAssembly>

    <dependentAssembly>

        <assemblyIdentity name="trim_coms.trim_combos.trim_combos" publicKeyToken="e02ee5289fcc8248" culture="neutral" />

    </dependentAssembly> 



   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

        <probing privatePath="bin_native"/>

   </assemblyBinding>

</runtime>

我的 dll 在头文件中定义为:

find_duplicates dll

namespace   find_dups
class       find_duplicates

trim_combos   dll

namespace   trim_coms
class       trim_combos

我在 Windows 7 64 位上以集成管道模式运行 IIS。这就是我在 web.config 中使用 system.webserver 部分而不是 system.web 部分的原因。

对此的任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • 您可以尝试以下方法之一:从 部分中删除版本、文化和 PublicKeyToken 或者在您的 部分中,添加 (对于两个 DLL)您还可以打开程序集绑定日志 (fuslog) 并查看绑定失败的确切位置:stackoverflow.com/a/1527249/190476
  • 我尝试从模块部分中删除额外的项目,但是当页面加载时它给了我一个运行时错误“无法加载类型”。我尝试 bindingRedirect 没有运气。如何正确找到 dll 版本?我尝试了项目中引用的dll的属性中列出的运行时版本4.0.30319。这是正确的版本吗?还是我需要使用 Powershell 来找到正确的版本?系统使用旧 dll 而不是项目中的 dll 的问题是旧 dll 没有命名空间和类。但是新的可以。我可以引用没有这些的 dll 吗?
  • 我使用 Powershell 来获取 dll 版本。对于我的项目 dll,当我使用 [System.Reflection.AssemblyName]::GetAssemblyName("find_duplicates.dll").Version 时,我得到 0.0.0.0。但是当我使用 [System.Reflection.Assembly]::LoadFrom("find_duplicates.dll").GetName().Version 我得到 4.0.30319。这个东西的意思是什么?另外它说它不在GAC 中。我应该添加它吗?
  • 我现在正在尝试没有额外信息的模块部分。现在是: 其中类型是“namespace.class”。但是现在当页面加载“无法加载类型”时出现运行时错误。我使用 Powershell 来获取旧 dll 和新 dll 的版本信息。版本是一样的。但是旧版本没有命名空间和类。这可能是错误的根源吗?如果运行时使用的是较旧的 dll,那么它找不到类型,因为没有。我从这里去哪里?
  • 现在我注释掉了 web.config 中的 system.webserver 部分,并且该应用程序在我的机器上运行良好。当我发布到我的共享主机站点时,页面加载并且所有选项都起作用,除了使用 dll 的 2 个选项。它收到错误“找不到 dll”。我正在使用 web.config 的运行时部分中的探测 privePath 来查找 bin_native 文件夹中的 dll,它适用于我的机器,但不适用于托管站点。我想知道为什么。该应用程序在根文件夹中找到一个名为 Files 的文件夹,以查找输入文本文件和输出 html 文件。为什么使用 bin_native 文件夹不起作用?

标签: asp.net


【解决方案1】:

我让它工作了。我的 dll 不是托管的(它们是本机模块),因此即使它们有一个类和一个命名空间,它也无法为它们加载类型。显然对于本机模块,您只需使用添加名称,没有别的,如下:

<system.webServer>

    <globalModules>

      <add name="find_duplicates"/>

    </globalModules>

  </system.webServer>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-07
    • 2012-03-06
    • 2011-10-28
    • 2017-07-30
    • 2013-11-10
    • 2011-01-31
    • 2010-11-07
    • 1970-01-01
    相关资源
    最近更新 更多