C# --- .Net Framework中的Binding Redirect

C# --- .Net Framework中的Binding Redirect

什么是Binding Redirect

  • 为什么需要绑定重定向?
  • 在.Net Framework 中, 假设你有一个应用程序 A,它引用了libray B 和 library C, 同时B又引用了D的1.1.1.0版本,而C引用了D的1.1.1.1版本. 现在我们面临一个冲突,因为在运行时无法加载不同版本的同一个程序集
  • 一般会报出以下Error Message
System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
  • 为了解决这个冲突,你可以使用绑定重定向,通常是指向新版本(但也可以指向旧版本)。你可以通过将以下内容添加到应用程序 A 的 app.config 文件的 configuration > runtime > assemblyBinding 部分来进行绑定重定向
//所有对D的 0.0.0.0-1.1.1.0 之间版本的引用都会重新定向到版本1.1.1.1
<dependentAssembly>
    <assemblyIdentity name="D" publicKeyToken="32ab4ba45e0a69a1"  culture="en-us" />  
    <bindingRedirect  oldVersion="0.0.0.0-1.1.1.0"  newVersion="1.1.1.1" />  
</dependentAssembly>

在.Net Core中可以使用如下方法

//You can add the following settings to your .csproj file:
<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
  • Otherwise adding them to an app.config in the root of the solution, as Joao says, works too. Make sure you set its Copy to Output Directory setting to Copy always or Copy if Newer.

相关推荐

  1. asp.netWebForm(.netFramework) CSRF漏洞

    2024-07-22 13:38:04       19 阅读
  2. C++ 引用

    2024-07-22 13:38:04       55 阅读
  3. c++引用(&)

    2024-07-22 13:38:04       51 阅读
  4. C++符号->

    2024-07-22 13:38:04       37 阅读
  5. C++预处理

    2024-07-22 13:38:04       56 阅读
  6. C++引用

    2024-07-22 13:38:04       44 阅读
  7. C# 接口

    2024-07-22 13:38:04       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 13:38:04       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 13:38:04       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 13:38:04       45 阅读
  4. Python语言-面向对象

    2024-07-22 13:38:04       55 阅读

热门阅读

  1. 深入语音识别:贝叶斯准则的细致解析

    2024-07-22 13:38:04       18 阅读
  2. 从统计学、到机器学习和ChatGPT

    2024-07-22 13:38:04       18 阅读
  3. MobaXterm远程工具

    2024-07-22 13:38:04       21 阅读
  4. 【TORCH】获取第一个batch数值的几种方法

    2024-07-22 13:38:04       19 阅读
  5. [Python]使用pyttsx3将文字转语音

    2024-07-22 13:38:04       14 阅读
  6. 【QT】线程控制和同步

    2024-07-22 13:38:04       15 阅读
  7. [基础算法理论] --- 双指针

    2024-07-22 13:38:04       18 阅读
  8. PHP银行卡实名认证接口对接、银行卡识别

    2024-07-22 13:38:04       17 阅读
  9. 27. 移除元素【 力扣(LeetCode) 】

    2024-07-22 13:38:04       17 阅读
  10. HTML5+CSS3学习笔记第一天

    2024-07-22 13:38:04       16 阅读
  11. LeetCode 常见题型汇总

    2024-07-22 13:38:04       16 阅读
  12. electron 主进程和渲染进程通信

    2024-07-22 13:38:04       14 阅读
  13. 一个养殖类的网站的设计

    2024-07-22 13:38:04       18 阅读