首页 > 解决方案 > 为什么在我的 ASP.Net Core 2.2 api 中尝试实现 UseNetTopologySuite 时出现此错误?

问题描述

我正在尝试在 Sql Server 和 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 中创建我的实体并将其注入应用程序的其余部分有关。

有想法该怎么解决这个吗?

标签: ef-core-2.0nettopologysuite

解决方案


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

一旦我安装了这个,它工作得很好。


推荐阅读