On a new machine I have VS2017 and MSSQL2016 installed. I create a project that installs EntityFramework 6.1.3 and Microsoft.SqlServer.Types 14.0.314.76 and uses spatial types. When running, you get 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"
The workaround is to set up a binding redirect to point from version 10.0.0.0 to version 14.0.0.0.
Further analysis:
In System.Data.Entity.SqlServer, the ctor for SqlTypesAssemblyLoader defaults to hardcoded assembly version checks of version 10.0 or 11.0 of Microsoft.SqlServer.Types.dll.
This check is problematic as the pace of release of EF is much slower than the pace of release of the Microsoft.SqlServer.Types nuget package [1]. I would think that the installation of the nuget package should do 1 of 2 things:
[1] https://www.nuget.org/packages/Microsoft.SqlServer.Types/
How about the EntityFramework package having a dependency on the Microsoft.SqlServer.Types packages (only drawback is the increased payload size) ?
EF Triage: we decided to add a mechanism that would allow an application to explicitly set the assembly to use. This would likely just be a static method on the SQL Server provider.
The redirect workaround works. Thank you.
Here is an example for anyone who might need it.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Update: Starting with 6.3, EF will now attempt to load 11.0.0.0, then 10.0.0.0, and if neither of those were found, it will load the latest x.0.0.0 version it can find. However, SQLClient has not been updated in this way, so for some types like HierarchyID, the binding redirect may still be needed.
@chrisg32 Adding the redirect fixed my issue perfectly. Many thanks! (EF 6.2 with v14.1 SqlServerTypes)
Thanks @chrisg32 that really worked out for me after struggling the whole weekend.
Most helpful comment
The redirect workaround works. Thank you.
Here is an example for anyone who might need it.