C# Microsoft.SqlServer.Types程序集导致地理数据类型出现问题。如何修复?

C# Microsoft.SqlServer.Types程序集导致地理数据类型出现问题。如何修复?,c#,asp.net,.net,sql-server,.net-assembly,C#,Asp.net,.net,Sql Server,.net Assembly,升级并将我的项目更改为目标网络.NET 4.8,并在package manager中将使用过的Nuget软件包升级到最新版本后。这带来了一系列问题。最紧迫的是无法在DataReader和实体框架中使用地理数据类型。 数据读取组件中的错误为: System.InvalidOperationException:DataReader.GetFieldType(x)返回null。 实体框架只是吞下了异常(这本身就是一个非常好的想法)并返回了空数据集 因为这些消息实际上毫无意义,也无助于揭示原因,所以我创

升级并将我的项目更改为目标网络.NET 4.8,并在package manager中将使用过的Nuget软件包升级到最新版本后。这带来了一系列问题。最紧迫的是无法在DataReader和实体框架中使用地理数据类型。 数据读取组件中的错误为: System.InvalidOperationException:DataReader.GetFieldType(x)返回null。 实体框架只是吞下了异常(这本身就是一个非常好的想法)并返回了空数据集

因为这些消息实际上毫无意义,也无助于揭示原因,所以我创建了一个简单的控制台应用程序来研究这个问题

简单的控制台应用程序

目标框架.NET4.8

已安装的nugget软件包Microsoft.SqlServer.Type版本14.0.1016.290

using System;
using System.Configuration;
using System.Data.SqlClient;

namespace TestGeo
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
            {
                sqlConnection.Open();
                using (SqlCommand sqlCommand = new SqlCommand( "SELECT TOP 1 Location FROM MyTable WHERE Location IS NOT NULL"))
                {
                    sqlCommand.Connection = sqlConnection;
                    //sqlCommand.CommandTimeout = 10;
                    SqlDataReader reader  = sqlCommand.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var type = reader.GetFieldType(0);    // <- This line causes exception.
                            Console.WriteLine(type.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("No rows.");
                    }
                    reader.Close();
                }
            }
        }
    }
}
使用系统;
使用系统配置;
使用System.Data.SqlClient;
命名空间TestGeo
{
班级计划
{
静态void Main(字符串[]参数)
{
使用(SqlConnection SqlConnection=newsqlconnection(ConfigurationManager.ConnectionStrings[“MyConnectionString”].ConnectionString))
{
sqlConnection.Open();
使用(SqlCommand SqlCommand=new SqlCommand(“从MyTable中选择位置不为NULL的前1个位置”))
{
sqlCommand.Connection=sqlConnection;
//sqlCommand.CommandTimeout=10;
SqlDataReader=sqlCommand.ExecuteReader();
if(reader.HasRows)
{
while(reader.Read())
{

var type=reader.GetFieldType(0);//这回答了你的问题吗?@IanKemp No,我已经看到了。@IanKemp顺便说一句,你投票赞成结束这个问题了吗?这回答了你的问题吗?@IanKemp No,我已经看到了。@IanKemp顺便说一句,你投票赞成结束这个问题了吗。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
    </startup>
  <connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=myserver.example.com;Initial Catalog=MyDatabase;User Id=MyUser;Password=supersecretpassword;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <runtime>
    <assemblyBinding>
    <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>
</configuration>