0

I am working on a WCF Service Application. i want to find closest location to someone. my porblem is when i want call any methods related to System.Data.Entity.Spatial.DbGeography i get this 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."

i installed Microsoft.SqlServer.Types by NuGet in Visual Studio 2017 solution and call load SqlServerTypes assemblies before any call to DbGeography class

    private bool _IsSqlServerTypesLoaded;
    private void CheckSqlServerTypes()
    {
        if (!_IsSqlServerTypesLoaded)
        {
           System.Data.Entity.SqlServer.SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.1016.290, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
            SqlServerTypes.Utilities.LoadNativeAssemblies(System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "bin"));
            _IsSqlServerTypesLoaded = true;
        }
    }

i am call CheckSqlServerTypes() before any attempt to query for locations but i still get this 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. "

what is my mistake?

Hamed
  • 15
  • 4

1 Answers1

0

i found my mistake and want to share, maybe useful for others

in code above i changed "Version=14.0.1016.290" to "Version=14.0.0.0"

also add this to web.config

<assemblyBinding>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
      <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>

and everything works fine

Hamed
  • 15
  • 4