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.
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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With