2016-04-18 84 views
1

我安裝了Nuget Microsoft.SqlServer.Types並且有DLL版本的問題。 我已閱讀自述與在Global.asax(網絡表單的Web應用程序)的添加行Microsoft.SqlServer.Types.SqlGeography DLL在GAC中

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

「」類型的異常出現在System.Data.DataSetExtensions.dll但沒有在用戶代碼中處理

附加信息:[A] Microsoft.SqlServer.Types.SqlGeography kan niet worden geconverteerd naar [B] Microsoft.SqlServer.Types.SqlGeography。類型A是上下文中的Microsoft.SqlServer.Types,版本= 10.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91默認操作位置C:\ WINDOWS \ assembly \ GAC_MSIL \ Microsoft.SqlServer.Types \ 10.0.0.0__89845dcd8080cc91 \ Microsoft.SqlServer.Types.dll。類型B是上下文中的Microsoft.SqlServer.Types,版本= 11.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91默認操作位置C:\ WINDOWS \ assembly \ GAC_MSIL \ Microsoft.SqlServer.Types \ 11.0.0.0__89845dcd8080cc91 \ Microsoft.SqlServer.Types.dll。

它沒有在這條線:

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

theLocation是地理數據類型在我的SQL Server 2008,所以對我來說沒有2016 FOR JSON PATH選項不幸。

ps。一些背景信息:我安裝了nuget GeoJSON.Net和GeoJSON.Net.Contrib.MsSqlSpatial以將geography數據類型行作爲geojson。或者我應該在我的sql中添加.tostring並將其解析爲geojson點?

回答

2

發現這裏從Arne Klein (8 May 2014 5:08 AM)

的負載的SqlClient默認Microsoft.SqlServer.Types版本10.0和與SQL Server需要2012 V. 11。通過將以下內容添加到web.config中可以解決此問題。

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

如果NuGet包可以被更新,以自動將其添加到web.config中這將是巨大的。

我同意Arne的說法,那就是很棒。