4

This has been asked many times, however after following the advice in this answer I am still coming up short.

I have a class library that gets invoked by another app. This works locally without issue. I use the following...

SqlServerSpatial140 and msvcr120 are both in the bin in their respective folders.

Before spatial calls are invoked

SqlServerTypes.Utilities.LoadNativeAssemblies(dlls); // dlls == bin directory 
SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;

App.config

<runtime>
  <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>
</runtime>

However when deployed onto a server I get a System.InvalidOperationException when calling System.Data.Entity.Spatial.DbGeography.FromText(String wellKnownText)

with 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. System.InvalidOperationException: 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 am I missing here?

IronAces
  • 1,857
  • 1
  • 27
  • 36
  • I had same issue, I installed Sql Server Management Studio on server and this issue disappeared. If you can't install SSMS then alternatively you can install Sql Server Developer Tools on server. Try this and let me know if it works, I will post this comment as an answer. – Akash Kava Dec 12 '20 at 07:04

1 Answers1

0

Have you placed the bindingRedirect in the executable applications App.config? Class libraries and other DLLs should avoid using App.config settings.

More info here:

https://stackoverflow.com/a/1009227/3850405

This bindingRedirect worked for me:

<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>

https://stackoverflow.com/a/44819952/3850405

Ogglas
  • 62,132
  • 37
  • 328
  • 418