#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

Solving the "Spatial types and functions are not available ..." -problem

koskila
Reading Time 3 min
Word Count 468 words
Comments 4 comments
Rating 4 (1 votes)
View

This page describes multiple ways to fix the  'Spatial types and functions are not available for this provider because the assembly ‘Microsoft.SqlServer.Types’ version 10 or higher could not be found.' exception which comes up during debugging or publishing your program, app or service using DbGeography.

Symptoms

While running a console program or perhaps installing an ASP.NET MVC website on a machine, where SQL Server (apart from the one that comes with the Visual Studio) has not been installed, you may encounter the following 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.

At least for me, this was baffling as that assembly was included in the project, and would compile and run flawlessly on other machines, just not on this one. I'm documenting here all the possible fixes to the issue I am aware of.

Problem / Reason

For me, the actual reason was that even though the DLL was loaded and included in the project as a nuget package, the actual native assemblies for this dll were not loaded to memory, as this needs to be done in the runtime. This issue was made worse by the fact that I first created this solution on a machine, where SQL Server was installed, so I was very much oblivious of the issue until it hit me on the face while trying to run my program on this particular machine, which did not have SQL Server.

Solution

After googling around, I found a few non-working solutions - they may work in other contexts, so I'm documenting them here.

Time needed: 5 minutes.

Try the following to fix the  'Spatial types and functions are not available for this provider because the assembly ‘Microsoft.SqlServer.Types’ version 10 or higher could not be found.' error

  1. Install the Microsoft.SqlServer.Types NuGet package.

    Install-Package Microsoft.SqlServer.Types
    

    For my other dev machine, this alone was enough to get me going.

  2. If you have it already, and the issue persists, reinstall it:

    Update-Package -reinstall Microsoft.SqlServer.Types
    

    For me, this added the much-needed dlls to the actual project, as they didn't exist on this machine (but did on the other, where I first ran this command).

    If it's still throwing the exception, you'll need to load the assemblies on the fly

  3. ASP.NET applications:

    For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:

    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
    
  4. Desktop applications

    For desktop applications, add the following line of code to run before any spatial operations are performed:

    qlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
    

    For the record, this worked for me.

  5. **
    If it's still not working, you can try installing the SQL server on the dev machine. Pain in the ass, I know, but it should fix the situation in case nothing else works.**

Good luck!

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Serdar
2017-03-01 15:55:02)
Hello. First of all thank you for solving the problem. I get the same error while running the test in the UnitTest project, and I keep getting the same error when I make the package install and reinstall. Have you tried anything for that?
2017-03-01 18:02:01
Hey Serdar, Thanks for your comment! I haven't, unfortunately.. Does the error occur even when running the tests locally? Have you been able to include the DLLs in the test project as well, using the instructions on step 3 in my blog post?
KMann3
2018-04-13 04:21:13)
I got this problem after rebuilding my machine and after many attempts and various Google searches -- this resolved the error. Thanks!
2018-04-16 00:54:11
Happy it helped! :)
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-19T05:06:23Z