16

I have a .NET MVC web application referencing System.Data.Spatial so I can use the DbGeography datatype on a property for some geolocation stuff. I'm using Visual Studio 2012 with .NET 4.5 and do not have a full installation of SQL Server on my development machine (only localdb).

The app works great until I push it to Azure. As soon as my app hits my DbGeography property, it throws this error:

Unable to load DLL 'SqlServerSpatial.dll': The specified module could not be found.

Has anyone else encountered this issue?

gofr1
  • 15,741
  • 11
  • 42
  • 52
ryanw51
  • 200
  • 1
  • 1
  • 7

8 Answers8

14

SqlServerSpatial.dll is unmanaged code. You have to install the correct version (64bit) on the server. Add the DLL to your project. Set the properties of SqlServerSpatial110.dll to “Copy to Output directory = Copy always”

You find detailed Information here

slfan
  • 8,950
  • 115
  • 65
  • 78
  • 1
    Thank you! I was trying to add a reference to the DLL, but as unmanaged code, that obviously doesn't work. I created a Lib directory in my project and stuck the file in there. – ryanw51 Jun 01 '13 at 17:46
  • @ryanw51 please, help. How do you mean by you created a 'lib' directory in your project, and stuck the file there. – sacretruth Oct 19 '13 at 07:35
  • @kooldave98 Create a new folder an your project, copy the SqlServerSpatial.dll into this folder and deploy it together with your project. – slfan Oct 19 '13 at 07:59
  • I'm using TFS Continuous Integration deployment to Azure. I have added the `SqlServerSpatial.dll` and even `SqlServerSpatial110.dll`. I have checked everything into TFS and a build and deployment has been done. I am still having the same problem. – sacretruth Oct 19 '13 at 08:03
  • 1
    @kooldave98 Did you read this? http://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/ – slfan Oct 19 '13 at 08:05
  • The blog post is kinda old, but I followed it and I got to the point where it says I needed to add project references to the DLLs. Now this is where I got stuck. VisualStudio doesn't let me add the project complaining that it is inaccessible and invalid – sacretruth Oct 20 '13 at 13:42
  • You can't add references to unmanaged code in a .NET project. Which DLL do you try to reference? – slfan Oct 20 '13 at 15:01
  • `SqlServerSpatial.dll` – sacretruth Oct 20 '13 at 15:23
  • the description doesn't say you have to add a reference to SqlServerSpatial.dll. You only have to add it to the project and do copy to output directory. You have to add a reference to Microsoft.SqlServer.Types.dll. – slfan Oct 20 '13 at 16:32
  • I've tried putting SqlSpacialTools.dll in my bin directory, but no dice :( – Ian Grainger May 10 '17 at 20:00
  • 1
    @IanGrainger did you reference Microsoft.SqlServer.Types.dll? Do you use the correct version (32/64bit)? – slfan May 10 '17 at 20:40
  • @slfan I've got past my error with the Microsoft.SqlServer.Types.dll - now I'm having an error with SqlSpacialTools.dll not found. I've tried Googling and getting the latest and putting it in System32, SysWOW64, and bin folder, but no dice... I'm wondering if I need an older version that's compatible with the original Microsoft.SqlServer.Types.dll. – Ian Grainger May 10 '17 at 21:03
  • Well I don't have IIS Express checked to run in 64 bit mode, and I have SqlServerSpacial.dll in System32 - and I've copied it to my bin directory. (I was looking for SqlSpacialTools.dll before, which was wrong - but this hasn't helped, either!) – Ian Grainger May 11 '17 at 05:43
  • Got it! I tried _checking_ 64 bit mode and it's worked. I took everyone saying 'make sure you have the right 32/64 bit version' as: get 64 bit, but of course, if IIS Express is 32 bit, I need to install the 32 bit version of the SQL Server 2008 System CLR Types! – Ian Grainger May 11 '17 at 08:05
2

SQL 2012 installs this dll too, SQL 2014 don't! You have to install the Microsoft System CLR Types for SQL Server 2008 R2 on the machine.

  1. http://www.microsoft.com/en-us/download/details.aspx?id=26728
  2. Click Download
  3. Check off one of these depending on your processor architecture:

    • 1033\x64\SQLSysClrTypes.msi
    • 1033\x86\SQLSysClrTypes.msi
    • 1033\IA64\SQLSysClrTypes.msi
  4. Click Next

Edit

as Ian Grainger's comment, you have to install the correct version based on your IIS. apparently IIS Express runs in 32bit mode by default.

Mahmood Dehghan
  • 7,761
  • 5
  • 54
  • 71
  • I did this and it's made no difference. – Ian Grainger May 10 '17 at 19:53
  • 2
    Hi, @Mahmoodvcs - please could you update this answer to mention that it's depending on the architecture of your IIS/IIS Express! I installed the correct one for my architecture (64), but IIS Express runs in 32 bit mode by default! – Ian Grainger May 11 '17 at 08:06
  • 1
    Most of this answer's text is taken from https://stackoverflow.com/a/14797013/11683 without attribution. – GSerg Oct 11 '21 at 13:14
2
<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="12.0.0.0" />
  </dependentAssembly>
  </assemblyBinding>
</runtime>
David Chen
  • 21
  • 1
1

I ran into this problem and was truly missing the SqlServerSpatial110.dll

I ended up following the instructions here:

http://dllyes.com/sqlserverspatial110-dll/

Basically you need to get your hands on that .dll and then

Place SqlServerSpatial110.dll in \Windows\System32 (usually located at disk C) if you’re running 32 bit Windows. If you’are running 64 bit Windows, additionally place file in \Windows\SysWOW64.

pflous
  • 573
  • 6
  • 17
  • This worked for me. I used nuget to download the SqlServerTypes assemblies to my solution but when I ran the EntityFramework command Add-Migration, it couldn't find the SqlServerSpatial140.dll. My IIS is 32bit but my Windows architecture is 64 bit, so I had to copy the 32 bit dll into C:\\Windows\\SysWOW64. If you run the command Add-Migration and get System.BadImageFormatException, then you have a 64 bit dll when it should be 32 bit. – nightwuffle May 15 '20 at 19:22
0

I was struggling with it for a quite some time, i installed required files, but it still wasn't working.

Apparently, the project wanted to use x86 SqlServerSpatial.dll So i changed the IIS Express Build to x64 in Tools>Options>WebProjects>Use the 64 bit IIS Here is the screen

There is no need of adding new nuget packages, just install the SQLSysClrTypes from microsoft page : http://go.microsoft.com/fwlink/?LinkID=188391&clcid=0x409 and it should be fine ;)

Hope that it helps someone!

0

Make sure that your dlls(such as "sqlserverspatial110.dll" , "sqlserverspatial120.dll" , ..) be in this path "C:\Windows\SysWOW64";

-1
  • SqlGeometry and SqlGeography types can be used in VS projects (e.g. C#) by referencing the Microsoft.SqlServer.Types.dll.
  • Microsoft.SqlServer.Types.dll is a managed library and has some unmanaged library as prerequisites and they are like SqlServerSpatialXXX.dll and msvcrXXX.dll
  • Since Sql Server 2008, different versions of Microsoft.SqlServer.Types.dll are available, however, I don't see any functionality change from 2012 on.

For a detailed solution you may want to see my answer on another similar post.

Community
  • 1
  • 1
Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
-1
I had the same issue in godaddy VPS with windows server 2012 r2

I Resolved it by Updating my EF5 to EF6

in package manager console run to EF5 to EF lalest

Install-Package EntityFramework 
Nur Uddin
  • 1,798
  • 1
  • 28
  • 38