bindingRedirect 没有克服 ReflectionTypeLoadException

bindingRedirect not overcoming ReflectionTypeLoadException

我有一个带有插件架构的 ASP.NET 项目。我的引用链中有一个强命名的 dll 依赖项,应用程序和插件都依赖于它。当使用新的依赖 dll 更新应用程序时,我真的希望能够使用一些针对旧版本的依赖 dll 编译的旧插件。

当前,当我调用 Assembly.GetTypes() 时,我得到一个 ReflectionTypeLoadException,其中有 5 个类型为 FileLoadException 的 LoaderExceptions,它们都抱怨同一个 dll。 (系统中有更多的dll,强命名和弱命名,也许依赖链导致LoaderExceptions中的重复?)

https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

我尝试添加到我的 web.config 文件中。

<runtime>
    <assemblyBinding>
        <dependentAssembly>  
            <assemblyIdentity name="Common.Production"  
            publicKeyToken="0e80e12b03b04a71"  
            culture="en-us" />  
            <bindingRedirect oldVersion="2.0.0.1459" newVersion="2.0.0.1463" />  
        </dependentAssembly>

但我仍然得到同样的错误。我尝试在依赖树中添加我知道的所有强类型 dll,错误消息或 LoaderExceptions 的数量没有变化。

IL DASM 显示我的密钥和版本正确,尽管它使用的语法略有不同:

.assembly extern Common.Production
{
  .publickeytoken = (0E 80 E1 2B 03 B0 4A 71 )                         // ...+..Jq
  .ver 2:0:0:1459
}

我的日志包含以下加载程序信息:

LOG: Using application configuration file: ...\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Common.Production, Version=2.0.0.1459, Culture=neutral, PublicKeyToken=0e80e12b03b04a71
...
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

is it possible to ignore assembly manifest mismatch? 如果签名密钥已更改,bindingRedirect 将不起作用。另一个针对更新版本构建的组件(在 IL DASM 中检查使用相同的 public 密钥标记。它没有改变:

.assembly extern Common.Production
{
  .publickeytoken = (0E 80 E1 2B 03 B0 4A 71 )                         // ...+..Jq
  .ver 2:0:0:1463
}

https://msdn.microsoft.com/en-us/library/ms973843.aspx

可能是?听起来有风险?程序集中不应该有我不使用的类型,这似乎稍后会咬我。

http://code.fitness/post/2016/12/assembly-binding-redirect.html

除了重新编译删除签名的依赖项并重新发布所有没有强命名引用而重新编译的插件之外,还有其他解决方案吗?部门中没有人(包括一位前成员)有充分的理由说明为什么这个库被强命名,但我们确实有理由不想重新编译插件。

Could not load file or assembly or one of its dependencies

参考链接:

https://johnnycode.com/2013/07/19/fixing-assembly-binding-redirect-errors/

我不知何故从我的 assemblyBinding 元素中遗漏了 xmlns 属性。

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