0

I have Visual studio 2015 community Edition with Update 3. I am using Entity Framework 6. On running the project on my local I am getting the error as shown in screen shot(https://puu.sh/uXFh0/64648902af.png). As in the code I am using c.Geography; its showing exception at that point.

I have Sql Server 2016 installed on my system with CLR Types as shown in below screen shot https://puu.sh/uXFqy/9f3c56a329.png

I also installed Sql server types using nuget package Install-Package Microsoft.SqlServer.Types.

Still no luck. what else can I do to solve the issue?

user1955255
  • 219
  • 4
  • 18

4 Answers4

1

You have multiple versions of the CLR types installed so you need to tell your application which version to use. Not sure what type of application it is but you need to either put these lines of code in your global.asax.cs (web app):

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";

or else this in your desktop app prior to the spatial code running:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
strickt01
  • 3,959
  • 1
  • 17
  • 32
0

Without entity framework I've solved this problem:

Try serialize Geography column on server and deserialize it back on your client

  1. Serialize to varbinary(max) (CAST(your_column as varbinary)) and deserialize it using SqlGeography.Deserialize(SqlBytes) method
  2. Serialize to WKB using SqlGeography.STAsBinary() and deserialize it using SqlGeography.STGeomFromWKB(SqlBytes, Int32)

1 is better, in case 2 you cannot pass srid (usually you don't need srid)

To use entity framework try this

  1. Declare this field as SqlBytes on you client
  2. view on server side can convert from Geography to varbinary
  3. if you have problems with update a view use stored procedure or instead of update/insert triggers

I think this is not beautiful solution, but it can help you to solve the problem

Mikhail Lobanov
  • 2,976
  • 9
  • 24
0

What worked for us was the answer at Assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. We installed the Microsoft System CLR Types for SQL Server 2012 and the problem was fixed.

Community
  • 1
  • 1
0

For the Microsft.SqlServer.Types error, you will need to install SQL Server 2012 Feature pack, even you have SQL 2016 installed. That is a pre-req. Check the below link

https://msdn.microsoft.com/en-us/data/dn194325

Ali Sakhi
  • 195
  • 1
  • 1
  • 9