0

I have these CLR types installed on my local https://puu.sh/yEWG5/b4f77fba7b.png

Also, I have SQL server 2016 installed on my local system but when I try to run the project I get error as below

https://puu.sh/yEWQm/78a4220830.png

Can someone help? I tried installing latest nugget package from https://www.nuget.org/packages/Microsoft.SqlServer.Types/ but it did not help.

Though I am able to add a column of type geography in a table in my local database. It fails at runtime when I run my project and error comes as below

https://puu.sh/yEWQm/78a4220830.png

user1955255
  • 219
  • 4
  • 18

2 Answers2

0

According to the docs if you have installed the CLR Types it should load from the GAC so I'm not sure why that didn't work for you. (I would check that you have the correct version as your dependency)

However, we do use the SQLServerTypes in our app without installing the CLR types by using the following method (this method is described in the readme.htm that comes with SqlServerTypes).

Grab the SqlServerTypes.nupkg and extract it to a folder lets call this folder SST from now on. (Locations of the files I talk about in the following steps may differ from version to version but, the principle is the same)

  1. Create a SqlServerTypes folder in your project
  2. Copy the SST/nativebinaries/x86 and x64 folders into your new SqlServerTypes folder
  3. Also copy the files from SST/content (you should see Loader.cs and readme.htm) into the SqlServerTypes folder.

Now all you need to do is call the Loader when your app boots up. We do this during our autofac setup by making this call.

Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory)

You may need to adjust the param passed into this method to work with your application. If the correct path is used you should have access to the spatial types in your code.

edit: It may be possible to just call the LoadNativeAssemblies straight away (and avoid all the work I posted above) if you have installed the nuget package in your app but, I have not tested this as we are stuck on an old version of SqlServerTypes.

Tim.E
  • 31
  • 4
0

Because i cannot put a comment i have to put a answer, you can check that, that article and this, this, this and this answers, i hope they guide you to someting usefull.