1
votes

I'm trying to do a code-first "add-migration" but I am getting the error:

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

I understand how to load the spatial DLL in the running app, but how do I do it when running a migration from the package manager?

Edit: OK, it's worse than I throught. This simple console app won't run because of the same error. I have Microsoft.SqlServer.Types installed from NuGet. Whats going on?

static void Main(string[] args)
        {
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
            System.Data.Entity.Spatial.DbGeography location = System.Data.Entity.Spatial.DbGeography.PointFromText("POINT(" + 10 + " " + 10 + ")", 4326);
        }

Exception: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

2

2 Answers

1
votes

OK, I got it working. There was something wrong with my environment. I uninstalled everything "SQL server" related on my system, installed VS 2017, installed "System CLR Types for Microsoft® SQL Server® 2012" and the error went away.

Not sure which thing fixed it, but if you're having the same issue, try uninstalling all "CLR Types for Microsoft® SQL Server" and try installing the latest.

-1
votes

Try to install Microsoft.SqlServer.Types from the Package Manager console:

PM> Install-Package Microsoft.SqlServer.Types