Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am attempting to use the geometry functionality in Sql Server and EF Core.

I've installed the following packages

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

In my Startup.cs, I have the following:

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

Everything builds fine, but when I attempt to run the app, I get the following error:

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)

I suspect this has to do with creating my entity in the Program.cs and injecting it into the rest of the app.

Any ideas on how to fix this?

like image 671
Scottie Avatar asked Aug 29 '19 23:08

Scottie


2 Answers

For anyone looking at this, it turns out that you need to install the NetTopologySuite.Core, not NetTopologySuite.

Once I installed this, it worked fine.

like image 61
Scottie Avatar answered Nov 20 '22 16:11

Scottie


You need to delete the NetTopologySuite library And just use Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite.

like image 9
Ehsan Babaei Avatar answered Nov 20 '22 15:11

Ehsan Babaei