wcf - 如何在 WCF 服务应用程序中使用 Microsoft.SqlServer.Types
问题描述
我正在开发 WCF 服务应用程序。我想找到离某人最近的位置。我的问题是当我想调用与 System.Data.Entity.Spatial.DbGeography 相关的任何方法时,我收到此错误“空间类型和函数不适用于此提供程序,因为程序集 'Microsoft.SqlServer.Types' 版本 10 或更高版本可能找不到。”
我在 Visual Studio 2017 解决方案中通过 NuGet 安装 Microsoft.SqlServer.Types 并在调用 DbGeography 类之前调用加载 SqlServerTypes 程序集
private bool _IsSqlServerTypesLoaded;
private void CheckSqlServerTypes()
{
if (!_IsSqlServerTypesLoaded)
{
System.Data.Entity.SqlServer.SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.1016.290, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
SqlServerTypes.Utilities.LoadNativeAssemblies(System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "bin"));
_IsSqlServerTypesLoaded = true;
}
}
在尝试查询位置之前,我调用了 CheckSqlServerTypes(),但我仍然收到此错误“空间类型和函数不适用于此提供程序,因为找不到程序集 'Microsoft.SqlServer.Types' 版本 10 或更高版本。”
我的错误是什么?
解决方案
我发现了我的错误并想分享,也许对其他人有用
在上面的代码中,我将“版本=14.0.1016.290”更改为“版本=14.0.0.0”
也将其添加到 web.config
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
一切正常
推荐阅读
- javascript - 延迟 for 循环不断返回相同的值
- angular - 在应用程序中嵌入相机
- sql - 2个表的SQL查询如何填充第一个到第二个表的字段
- php - PHP从数组和关联的行数据中获取最小值?
- active-directory - LDAP 获取 Active Directory 中用户的主要组名
- .net - 缺少 Visual Studio“目标框架”
- sql - 在 SQL 中计算单列之后的行数
- python - 从 aws lambda 函数与 mongodb 通信
- python - 使用 keras 但出现错误 AttributeError: 'Tensor' object has no attribute '_keras_history'
- javascript - 带有 readonly 属性的小部件不会打开