Ef6: Microsoft.SqlServer.Types hardcoded to use 10.0 or 11.0

Created on 12 Apr 2017  Â·  6Comments  Â·  Source: dotnet/ef6

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. Create the binding redirect for you when installing the nuget package in the app/web.config. This would ensure things are always pointing to the latest and proper version.
  2. Use the Loader.cs class to specify the currently installed version to pass in to SqlTypesAssemblyLoader.

[1] https://www.nuget.org/packages/Microsoft.SqlServer.Types/

closed-fixed type-enhancement

Most helpful comment

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>

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnReZa picture AnReZa  Â·  4Comments

ErikvdBurgwal picture ErikvdBurgwal  Â·  6Comments

jozsurf picture jozsurf  Â·  8Comments

domagojmedo picture domagojmedo  Â·  7Comments

PhilPJL picture PhilPJL  Â·  7Comments