引用其他项目时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
相关产品推荐
相关产品推荐

