You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

.NET Framework升级至4.8后遇程序集冲突,求助解决System.Runtime/System.IO问题

解决.NET Framework 4.8升级后的System.Runtime和System.IO版本冲突问题

我来帮你搞定剩下的System.Runtime和System.IO版本冲突,思路和你修复System.Net.Http的方法一致,再结合几个关键步骤就能解决:

1. 手动修改.csproj中的引用配置

和你处理System.Net.Http的方式一样,直接在项目文件里给System.Runtime和System.IO的引用加上明确的版本、公钥令牌等属性,强制指定要使用的版本。

示例修改(System.Runtime):

原引用可能类似:

<Reference Include="System.Runtime">
  <HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
  <Private>True</Private>
</Reference>

修改为:

<Reference Include="System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
  <Private>True</Private>
</Reference>

示例修改(System.IO):

原引用可能类似:

<Reference Include="System.IO">
  <HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
  <Private>True</Private>
</Reference>

修改为:

<Reference Include="System.IO, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
  <Private>True</Private>
</Reference>

注意:请根据你实际的NuGet包版本调整HintPath中的路径。

2. 添加/更新程序集绑定重定向

仅仅修改csproj还不够,需要在app.configweb.config中添加绑定重定向,告诉CLR自动将旧版本的程序集请求重定向到你指定的新版本。在<runtime>节点下添加以下配置:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <!-- System.Runtime 重定向 -->
  <dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <!-- System.IO 重定向 -->
  <dependentAssembly>
    <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
</assemblyBinding>

3. 重新安装相关NuGet包

执行以下命令,强制重新安装适配.NET Framework 4.8的System.Runtime和System.IO包,确保包版本与当前框架完全兼容:

Update-Package -Id System.Runtime –reinstall
Update-Package -Id System.IO –reinstall

4. 清理并重新生成解决方案

最后,清理解决方案(右键解决方案 → 清理),删除项目的binobj文件夹,然后重新生成项目,清除可能残留的旧程序集缓存。

这些步骤应该能彻底解决System.Runtime和System.IO的版本冲突问题,原理就是通过明确版本配置和绑定重定向,让CLR统一使用指定的兼容版本,避免不同依赖项请求不同版本导致的冲突。

内容的提问来源于stack exchange,提问作者Stackedup

火山引擎 最新活动