被忽略的“bindingredirect”无缘无故开始工作

问题描述

我有许多生成 dll 的项目和一个生成可执行文件的主项目,今天我成功编译了这些项目,但是当我尝试启动主项目时,我第一次遇到了下一个异常:“汇编清单定义没有不匹配程序集引用”,所以这不是我第一次重新编译项目并毫无问题地执行主要项目,但现在我收到了这个错误

检查异常后,我可以在 app.config 中找到导致它的“bindingredirect”,我检查了旧版本的系统,问题是这个“bindignredirect”始终存在于 app.config 中,但是以前从未抛出此错误,如果我评论 bindingredirect 行,则主项目开始时没有问题。

所有项目都以 .net 3.5 作为目标 .net 版本,这是什么原因造成的?有什么变化可以让 bindingredirect 现在得到执行?

App.config 部分

<!-- Habilita el debug just-in-time. -->
  <system.windows.forms jitDebugging="true" />
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Componentes" publicKeyToken="BB48DC83EB7CD949" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.1.17726" newVersion="1.0.1.17261" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

InnerException 的 FusionLog

=== Información de estado anterior al enlace ===
LOG: Usuario = ymora
LOG: displayName = Componentes,Version=1.0.1.17265,Culture=neutral,PublicKeyToken=bb48dc83eb7cd949
 (Fully-specified)
LOG: Appbase = file:///E:/Yerald Mora/Documents/SIstemAS/Principal/bin/
LOG: PrivatePath inicial = NULL
Ensamblado de llamada : Principal,Version=1.0.1.27092,PublicKeyToken=c078d737fbb55d54.
===
LOG: Este enlace empieza en el contexto de carga default.
LOG: Utilización del archivo de configuración de la aplicación: E:\Yerald Mora\Documents\SIstemAS\Principal\bin\Principal.vshost.exe.config
LOG: Utilizando el archivo de configuración del equipo en C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Redirección detectada en el archivo de configuración de aplicaciones: 1.0.1.17265 se redirigió a 1.0.1.17261.
LOG: Referencia posterior a la directiva: Componentes,Version=1.0.1.17261,PublicKeyToken=bb48dc83eb7cd949
LOG: Ya se detectó el mismo enlace,que generó un error hr = 0x80131040.

解决方法

使用旧版本的系统进行测试时,我意识到 dll 的版本号,在它的修订号中以高于 17 的数字开头,例如 1.0.1.18463,这就是问题所在!。 ..,在 app.config 的下一行中, 0.0.0.0 和 1.0.1.17726 之间的任何版本都应该重定向到 1.0.1.17261

(product_id,time)

InnerException的FusionLog下一行显示dll版本1.0.1.17265被重定向到1.0.1.17261

<bindingRedirect oldVersion="0.0.0.0-1.0.1.17726" newVersion="1.0.1.17261" />

因此,当我编译项目 Visual Studio 时生成的修订号为 17265,该修订号在 appconfig 中确定的范围内,这就是之前未出现问题的原因,因为修订号始终超出了当时确定的范围appconfig 的属性 bindingredirect