迁移.Net MVC应用后遇Microsoft.SqlServer.Types版本错误如何解决?
解决.NET Framework MVC应用迁移后Microsoft.SqlServer.Types程序集绑定错误
将基于.NET Framework 4.7.2的C# MVC应用从Windows Server 2012+SQL Server 2016环境迁移至Windows Server 2019+SQL Server 2019环境后,应用启动正常但运行时抛出错误:
Spatial types and functions are not available for this provider because the assembly Microsoft.SqlServer.Types version 10 or higher could not be found
排查过程
- 检查服务器环境,确认已安装Microsoft.SqlServer.Types 14版本,与错误提示描述矛盾
- 安装SQL Server 2019对应的Microsoft System CLR Types组件,问题未得到解决
- 尝试将项目的Microsoft.SqlServer.Types NuGet包更新至160.1000.6版本,因旧文件无法覆盖导致更新失效;删除项目中包含SqlServerSpatial140.dll的SQLServerTypes、x86及x64目录后重新更新,仍未解决问题
解决方案
最终定位问题为web.config中的程序集绑定重定向配置未同步更新:
原绑定配置:
<dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" /> </dependentAssembly>
将版本号调整为与NuGet包匹配的16版本:
<dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" /> </dependentAssembly>
修改配置后重新部署应用,问题彻底解决。
注:本次操作使用Visual Studio 2022完成
内容的提问来源于stack exchange,提问作者kevins1966
相关产品推荐
相关产品推荐

