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

引用其他项目时SQLClient失效:无法加载System.Data.SqlClient程序集

问题修复方案:Blazor调用旧DAL时找不到System.Data.SqlClient

问题背景

将Silverlight应用迁移至Blazor/Razor前端,对接.NET Framework 4.8的InternalDAL时,调用FillWithPendingById方法触发错误:

Could not load file or assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

已尝试安装NuGet包、升级DAL框架版本等操作,但问题未解决,希望无需重写查询即可修复。


修复步骤

1. 添加程序集绑定重定向

在Blazor Server项目的web.config中添加程序集重定向规则,明确指定System.Data.SqlClient的版本:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlClient" 
                          publicKeyToken="b03f5f7f11d50a3a" 
                          culture="neutral" />
        <!-- 替换newVersion为你实际安装的NuGet包版本 -->
        <bindingRedirect oldVersion="0.0.0.0-4.8.5.0" newVersion="4.8.5.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

版本号可从NuGet包管理器中查看已安装的System.Data.SqlClient版本

2. 统一DAL与Blazor项目的SqlClient引用

  • 打开InternalDAL项目,移除原有的System.Data.SqlClient系统引用
  • 通过NuGet安装相同版本的System.Data.SqlClient包,保证和Blazor项目中的版本一致

3. 清理重建解决方案

  • 手动删除所有项目的bin和obj文件夹
  • 在Visual Studio中依次执行:清理解决方案 → 重建解决方案
  • 重启Visual Studio,清除编译缓存

4. 验证TableAdapter配置

打开InternalDAL中的PaymentDataSet.xsd设计器:

  • 检查TableAdapter的连接字符串是否正确
  • 确认连接字符串的提供者为System.Data.SqlClient

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 08:12:42