为什么在我的 ASP.Net Core 2.2 api 中尝试实施 UseNetTopologySuite 时出现此错误?

Why am I getting this error when trying to implement UseNetTopologySuite in my ASP.Net Core 2.2 api?

我正在尝试使用 Sql 服务器和 EF Core 中的几何功能。

我已经安装了以下软件包

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="2.2.6" />
<PackageReference Include="NetTopologySuite" Version="2.0.0" />

在我的 Startup.cs 中,我有以下内容:

services.AddDbContextPool<CRFlowContext>(options => 
    options.UseSqlServer("connection string", x => x.UseNetTopologySuite());
});

一切正常,但是当我尝试 运行 应用程序时,出现以下错误:

Application startup exception: System.MissingMethodException: Method not found: 'GeoAPI.IGeometryServices NetTopologySuite.NtsGeometryServices.get_Instance()'.
at Microsoft.Extensions.DependencyInjection.SqlServerNetTopologySuiteServiceCollectionExtensions.AddEntityFrameworkSqlServerNetTopologySuite(IServiceCollection serviceCollection)
at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerNetTopologySuiteOptionsExtension.ApplyServices(IServiceCollection services)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
at Entities.CRFlowContext..ctor(DbContextOptions`1 options) in C:\Src\myproj\myproj.Entities\MyProjContext.cs:line 11
at lambda_method(Closure )
at Microsoft.EntityFrameworkCore.Internal.DbContextPool`1.Rent()
at Microsoft.EntityFrameworkCore.Internal.DbContextPool`1.Lease..ctor(DbContextPool`1 contextPool)

我怀疑这与在 Program.cs 中创建我的实体并将其注入应用程序的其余部分有关。

关于如何解决这个问题有什么想法吗?

对于看到这个的任何人,事实证明您需要安装 NetTopologySuite.Core,而不是 NetTopologySuite。

我安装后,它运行良好。

您需要删除 NetTopologySuite 库 只需使用 Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite.