You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET(C#)引用版本7却加载System.Configuration.ConfigurationManager版本9失败

解决System.Configuration.ConfigurationManager版本冲突问题

你贴出的<configSections>配置不会引发这个版本冲突——这段配置引用的是System程序集(版本4.0.0)中的类型,和System.Configuration.ConfigurationManager是完全独立的两个程序集,彼此不存在版本关联。

针对你遇到的问题,可以按以下步骤排查解决:

  • 清理本地NuGet缓存:执行命令 dotnet nuget locals all --clear,彻底清除缓存中残留的9.0.0版本包,避免干扰依赖解析
  • 检查项目的.lock.json文件:搜索System.Configuration.ConfigurationManager字段,查看是否有间接依赖偷偷引入了9.0.0版本。如果找到,可通过NuGet的依赖约束强制指定使用7.0.0版本
  • 添加程序集绑定重定向:在App.Config的<configuration>节点内加入以下配置,将对9.0.0版本的请求重定向到7.0.0:
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Configuration.ConfigurationManager" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="7.0.0.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>
  • 检查全局程序集缓存(GAC):打开命令提示符,执行 gacutil -l System.Configuration.ConfigurationManager,若发现9.0.0版本存在,用 gacutil -u System.Configuration.ConfigurationManager, Version=9.0.0.0 卸载该版本
  • 清理项目输出目录:手动删除项目的bin和obj文件夹,重新生成项目,避免残留的旧版本程序集导致编译异常

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 00:42:15