最近需要完成一个API,通过用户上传的经纬度判断用户的所在县市省,数据量相对不是很大所以把相关数据全部扔到了内存里知行,主要用到了SqlGeometry,
代码写完后运行本地没问题,扔到服务器上开始报异常“无法加载sqlserverspatial.dll”,一时蛋疼菊紧。难道还得装个sql server的服务吗。。。显然不用- -留下点笔记以备后用。。
Any application that uses Entity Framework’s spatial data type support to target SQL Server requires the ‘CLR Types for SQL Server’ to be available on the machine the application runs on. This also applies to applications that use SQL Server spatial data types directly, without using Entity Framework.(就是说想用SQL Server的空间模块功能一般得装个CLR Types for SQL Server)
When developing your application the CLR Types for SQL Server are usually installed system-wide, since they are included in Visual Studio. Issues arise when you try to deploy to a machine that does not have the CLR Types for SQL Server installed. Initially you will get the following InvalidOperationException.
Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.
If you were to find and deploy the Microsoft.SqlServer.Types assembly you’ll then get the following DllNotFoundException.
Unable to load DLL 'SqlServerSpatial110.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) ()
(正常思路是引用Microsoft.SqlServer.Types.dll就以为OK了。。然而依然会有异常)
解决方案:
安装 Microsoft.SqlServer.Types NuGet package.
打开引用仔细看了看,明明哪里都是版本11.0.0.0
解决方式:
在配置文件中添加对指定程序集
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>