gpt4 book ai didi

c# - 类型 'Microsoft.SqlServer.Types.SqlGeography' 存在于 'Microsoft.SqlServer.Types.dll' 和 'Microsoft.SqlServer.Types.dll' 中

转载 作者:太空狗 更新时间:2023-10-29 23:12:56 28 4
gpt4 key购买 nike

在我的 Windows 类库(由 MVC 网站使用)中,我安装了 NugetPackage Microsoft.SqlServer.Types (Spatial)

现在,我正在使用 ado.net 尝试读取值:

protected SqlGeography MapSqlGeography(DbDataReader reader, string key)
{
return reader[key] is DBNull ? null : (SqlGeography)reader[key];
}

如果我在此行中添加一个制动点,并在 visual studio watch 窗口中输入:“reader[key]”,我可以看到正确的 Point(XXXX,XXX) 类型:“object {Microsoft .SqlServer.Types.SqlGeography"

但是,一旦我尝试进行转换,我就会遇到以下错误:

(SqlGeography)reader[key]   The type 'Microsoft.SqlServer.Types.SqlGeography' exists in both
'Microsoft.SqlServer.Types.dll' and
'Microsoft.SqlServer.Types.dll'

主要的奇怪事实是 dll 完全相同......

据我所知,这个 namespace /类名只有一个“来源”,不应重复....

我的“用法”是:

using Microsoft.SqlServer.Types;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Threading.Tasks;

关于如何解决这个问题的任何想法?谢谢。

更新#1

我卸载了 NugetPackage `Microsoft.SqlServer.Types (Spatial)' 并尝试了一个名为:'Microsoft.SqlServer.Types (Unofficial)' 甚至在清理了所有以前的文件夹/文件并清理了“bin/obj”,我仍然有完全相同的异常....

我现在确实明白了造成这种情况的原因……如果有任何想法,我们将不胜感激。

更新#2

刚刚尝试使用extern alias destination;

return reader[key] is DBNull 
? null
: (destination.Microsoft.SqlServer.Types.SqlGeography)reader[key];

并且有异常(exception):

Cannot cast 'reader[key]' (which has an actual type of 'Microsoft.SqlServer.Types.SqlGeography') 
to
'Microsoft.SqlServer.Types.SqlGeography'
Microsoft.SqlServer.Types.SqlGeography

最佳答案

我今天遇到这个错误是因为引用的库包含来自 Nuget 的 Microsoft.SqlServer.Types 版本与本地安装的版本不同。

您可以使用 Nuget 安装匹配的版本来解决问题,或者如果这不是一个选项,您可以使用绑定(bind)重定向。

例如:

Install-Package Microsoft.SqlServer.Types -Version 10.50.1600.1

通过查看依赖项的 package.json 检查您的特定版本,或者您可以直接检查 DLL 属性。

关于c# - 类型 'Microsoft.SqlServer.Types.SqlGeography' 存在于 'Microsoft.SqlServer.Types.dll' 和 'Microsoft.SqlServer.Types.dll' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40929525/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com