.net - 为什么程序集绑定(bind)重定向在我的网站中不起作用?

标签 .net asp.net assemblies

我有一个使用内置开发 Web 服务器从 Visual Studio 运行的网站项目。网站的虚拟路径设置为/
web.config 包含一个运行时元素

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="CMS.Controls" publicKeyToken="834b12a258f213f9" culture="neutral" />
      <bindingRedirect oldVersion="4.1.3518.21577" newVersion="4.1.3561.21846" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

我已经删除了 xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"来自根的属性 configuration元素。

这是错误:

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



这是绑定(bind)的日志:
The operation failed.
Bind result: hr = 0x80131040. No description available.
...
LOG: DisplayName = CMS.Controls, Version=4.1.3518.21577, Culture=neutral, PublicKeyToken=834b12a258f213f9
 (Fully-specified)
...
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Project\WebSite\web.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: CMS.Controls, Version=4.1.3518.21577, Culture=neutral, PublicKeyToken=834b12a258f213f9
...
LOG: Assembly Name is: CMS.Controls, Version=4.1.3561.21846, Culture=neutral, PublicKeyToken=834b12a258f213f9
WRN: Comparing the assembly name resulted in the mismatch: Revision Number

在我看来,它似乎忽略了我的重定向。我已经看了一个小时了,是我有错别字吗?

最佳答案

我知道已经有一段时间了,但也许这可以在某个时候帮助某人......

我们在某个项目上遇到了完全相同的问题,
它是一个 Web 应用程序,而不是一个网站,但问题涉及到引用的程序集
我不认为项目类型的差异是相关的(我可能是错的)

假设我们有以下程序集:

  • 网络应用程序集
  • CMS 控制组件
  • 用户管理组件

  • WebApplicationAssembly 引用 CMSControlAssembly 和 UserManagementAssembly。

    因此,我们尝试在 CMSControlAssembly 上进行程序集绑定(bind),并取得了与您一样多的成功。

    经过一番挖掘后,灯亮了:

    问题是我们直接在我们的 web 应用程序中使用了 CMSControlAssembly 中的 web 控件。 (装配绑定(bind)是考虑到这一点的)

    但是 CMSControlAssembly 也被 UserManagementAssembly 引用,这就是我们问题的原因。

    UserManagementAssembly 编译时使用的 CMSControlAssembly 版本低于 Web 应用程序使用的版本。

    Web 应用程序找不到这个较低版本的程序集,因为提供的唯一版本是程序集绑定(bind)的目标版本。

    所以实际上错误不是显示非功能性程序集绑定(bind),而是 UserManagementAssembly 缺少程序集。

    关于.net - 为什么程序集绑定(bind)重定向在我的网站中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1543132/

    相关文章:

    javascript - .NET 中是否有类似于 Java 的 scripting.dev.java.net 的等效脚本编写方法?

    asp.net - 调试 ASCX 控制

    c# - 将 System.Drawing 位图转换为 Dlib Array2D

    c# - 将多个参数传递给 client.PostAsJsonAsync 函数

    c# - Javascript QueryString 到 c#

    javascript - 仅显示下拉 ajaxToolkit 中匹配的搜索模式项 :ListSearchExtender

    c# - 我有一个 c sharp dll。我怎样才能使它在其他语言(例如 PHP 或 Delphi)中可用?

    .net - .NET 程序集的 LoadFile 和 LoadFrom 之间的区别?

    .net MVC3 有条件地验证依赖于父对象属性的属性

    c# - 部署使用 DirectX 程序集的 C# 应用程序