1
votes

I installed the Nuget Microsoft.SqlServer.Types and have a version of DLL issue. I have read the readme and added the line in the global.asax (Webform web app)

protected void Application_Start(object sender, EventArgs e)
{
    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
}

An exception of type 'System.InvalidCastException' occurred in System.Data.DataSetExtensions.dll but was not handled in user code

Additional information: [A]Microsoft.SqlServer.Types.SqlGeography kan niet worden geconverteerd naar [B]Microsoft.SqlServer.Types.SqlGeography. Type A is afkomstig uit Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 in de context Default op locatie C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll. Type B is afkomstig uit Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 in de context Default op locatie C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll.

It failed on this line:

var bla = myDataTable.AsEnumerable().Select(x => new
{
    Loc = x.Field<Microsoft.SqlServer.Types.SqlGeography>("theLocation") // breaks
}).ToList();

theLocation is of datatype geography in my Sql Server 2008, so no 2016 FOR JSON PATH option for me unfortunatly.

ps. some background info: I installed nuget GeoJSON.Net and GeoJSON.Net.Contrib.MsSqlSpatial to get the geography datatype rows as geojson. Or should I just add .tostring in my sql and parse it as geojson point?

1

1 Answers

3
votes

Found here from Arne Klein (8 May 2014 5:08 AM)

The SqlClient loads by default the Microsoft.SqlServer.Types Version 10.0 and with SQL Server 2012 V. 11 is needed. This problem can be solved by adding the following to the web.config.

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

It would be great if the Nuget package could be updated to automatically add this to the web.config.

I agree with Arne, that addition would be great.