.NET 4.5 Beta DbGeography NotImplementedException
Asked Answered
P

4

7

I have a brand new server which I installed the .NET 4.5 Beta redistributable on. I am getting a NotImplemented exception when trying to use the spatial features. This code...

var x = DbGeography.PointFromText(string.Format("POINT({0} {1})", -45, 45), 4326);

Throws this exception...

System.NotImplementedException: The method or operation is not implemented.
at System.Data.Spatial.DefaultSpatialServices.GeographyPointFromText(String geographyText, Int32 spatialReferenceSystemId)

If I install the full VS.NET 11 Beta then the code works fine. Any ideas why? What is missing?

UPDATE FOR ANSWER

Thanks to Pawel. You need to have the SQL CLR Types installed. You can get the 2012 version at this link:

Microsoft® System CLR Types for Microsoft® SQL Server® 2012 http://www.microsoft.com/download/en/details.aspx?id=29065

OPINION

I really dont understand why the .NET framework has a dependency on SQL Server. There is nothing special about these classes. I realize this is likely a historical thing where the code was originally written by the SQL team and the .NET team wanted to reuse it. It's not very clear that this is a provider-based implementation either. A better exception message would have saved a day's work.

Pleasantry answered 12/4, 2012 at 3:30 Comment(5)
The reason for the dependency is actually to be platform independent. EF exposes DbGeography and DbGeometry types (which are platform agnostic) to the user but databases have their own spatial types they understand. Sql Server has its own spatial types but Oracle will have its own spatial types. Spatial provider needs to translate EF spatial types to types that database understands. Since you are using SqlServer the SqlServer specific spatial provider translates DbGeometry and DbGeography types to Sql Server specific types. Sql Server does not understand DbGeography or DbGeometry.Reverso
But that code is not using SQL Server; its just a single line of .NET code. Im not interacting with a database at all. What if I wanted to build an in-memory geospatial application? Why cant I do that with just .NET?Pleasantry
Building the whole spatial functionality is out of scope of Entity Framework and it would be copying what already has been done by SqlServer team. We don't have the expertise and we would rather spend this time on new features of the Entity Framework. If you need to use spatial types without database you will probably be better off using a specialized type library that focuses solely on spatial functionality. It will probably perform better too.Reverso
Hmmm... I added a reference to Microsoft.SqlServer.Types and EFCF5 and I don't see a DbGeography type. Does this only work with .NET 4.5 or also on 4.0?Raycher
Sorry, I missed your comment. In EF5 spatial types are only available in .NET Framework 4.5. In EF6 spatial types are available on both .NET Framework 4 and .NET Framework 4.5.Reverso
R
16

DefaultSpatialServices in Entity Framework are using SqlGeography and SqlGeometry types as backing types. These two types live in Microsoft.SqlServer.Types.dll assembly that is not part of the .NET Framework. The exception is thrown when EF cannot find these types (the exception could be more helpful...). When you install Visual Studio it will install localdb on your machine (or you may already have a SqlExpress database) and this is probably the way how you got the type on the machine that is working. On a machine where there is only .NET Framework installed and not Sql Server you won't have these types. You can either install SqlExpress on the box where you get the exception or you can try installing just the types. I am not sure where to get the assembly itself but I think the Sql Server feature pack (http://www.microsoft.com/en-us/download/details.aspx?id=27596) may have it. Types from SqlServer 2008 and SqlServer 2012 are supported so it should not matter which version you install.

EDIT

In EF6 the exception will contain a better message see: https://entityframework.codeplex.com/SourceControl/changeset/b3eca2c141c0fb517504f9731dc8ba7a9c5727ee

Work item used to track this bug: https://entityframework.codeplex.com/workitem/3

Reverso answered 12/4, 2012 at 21:13 Comment(3)
Thanks! You are correct. Ill update the question with the answer.Pleasantry
@Reverso I'm using DbGeography type on Azure and have ran into this issue. How do I install this on a Azure.?Can I just include Microsoft.SqlServer.Types.dll to my web project?Rainfall
Nevermind. using nuget Install-Package Microsoft.SqlServer.Types did the trickRainfall
N
2

Perhaps someone can highlight darwindaves answer:

Install nuget package Microsoft.SqlServer.Types. Alternatively add references to:

c:\Program Files(x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll and be sure to mark copy local in the properties.

Nedi answered 9/7, 2013 at 21:36 Comment(0)
R
1

The accepted answer by @Pawal helped solve my same problem. His link to "Microsoft SQL Server 2008 Service Pack 3 Feature Pack" left me a bit in the dark regarding what I actually needed to install on the target machine, but eventually established I only needed the following:

ENU\x64\SQLSysClrTypes.msi

Raye answered 4/12, 2018 at 11:10 Comment(0)
R
0

In addition to adding

c:\Program Files(x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll

I also needed to add

SqlServerSpatial110.dll

Once we added those it worked like a charm!

Rhubarb answered 15/12, 2017 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.