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

3

7

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?

Mantoman answered 29/8, 2019 at 23:38 Comment(0)
M
8

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.

Mantoman answered 2/9, 2019 at 15:44 Comment(1)
Additionally the package has to be installed in the library where the geometry or point types are used. Had Point in my domain and that was referencing NetTopologySuite, but repository layer had NetTopologySuite.Core. Once switched the package in the consuming library, update-database came green.Abbasid
L
12

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

Leopardi answered 14/10, 2019 at 13:45 Comment(1)
Pretty sure this is the correct answer. It's the one I was given for PostGreSQL, anyway: github.com/npgsql/efcore.pg/issues/1024Weiss
M
8

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.

Mantoman answered 2/9, 2019 at 15:44 Comment(1)
Additionally the package has to be installed in the library where the geometry or point types are used. Had Point in my domain and that was referencing NetTopologySuite, but repository layer had NetTopologySuite.Core. Once switched the package in the consuming library, update-database came green.Abbasid
L
0

If you want to use postgres in your dotnet project, you can use the UseNetTopologySuite after installing Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite

Lawana answered 6/10 at 5:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.