1
votes

Problem is pretty simple. I moved a WebApps project to Service Fabric which had the Microsoft.SqlServer.Types nuget package installed. Now, when trying to access database I'm getting the following error because I'm using spatial types.

"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've tried adding the following line of code to the class which the FabricRuntime creates an instance of, but that was of no use.

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

Your help would be appreciated, please do let me know if you need more info from me.

1

1 Answers

1
votes

You do need the line of code, but for asp.net application it should be slightly different: For Asp.net websites, Default.aspx.cs:

public partial class _Default : System.Web.UI.Page
{
    static bool _isSqlTypesLoaded = false;

    public _Default()
    {
        if (!_isSqlTypesLoaded)
        {
            SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
            _isSqlTypesLoaded = true;
        }

    }
}

For web applications, in Global.asax.cs:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

Also you need to create the following binding redirect in web.config:

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

Here is the only discussion on the topic which helped me.

Update: Here is a blog post that provides a well described solution in 3 steps. Although, the third step didn't work for me and I had to create the binding as described above.