npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.54k stars 226 forks source link

Starting a project using NetTopologySuite fails #1024

Closed pierrosv closed 5 years ago

pierrosv commented 5 years ago

I followed the instructions to enable the use of postgis in my .net EF Core 2.2 project but once the DbContext initializes I get the following error.

Could not load type 'GeoAPI.NetTopologySuiteBootstrapper' from assembly 'NetTopologySuite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1'.

roji commented 5 years ago

Any chance you're trying to use EF Core 2.2 with Npgsql 4.1.0? If so, that's not going to work. Npgsql.NetTopologySuite 4.1.0 will only work with Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite 3.0.0 and vice versa.

pierrosv commented 5 years ago

@roji

Hi thank you for your reply. I am using the following versions:

NetTopologySuite (2.0.0) Npsql.EntityFrameworkCore.PostgreSQL (2.2.4) Npsql (4.0.10) Npsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite (2.2.4) Npsql.NetTopologySuite (4.0.10)

I haven't been able to locate any references to a similar issue. I build a project from scratch using the latest stable versions for all relevant libraries. Let me know if there is something else I can share wih you.

image

roji commented 5 years ago

Somewhere in your dependency graph, NetTopologySuite 2.0.0 is being referenced - that is the problem.

Try doing dotnet restore again, Anne of it still doesn't work, post your csproj.

pierrosv commented 5 years ago

@roji

Thank you very much for your help. That was the issue. I was referencing NetTopologySuite to get access to Point, Polygon etc. but actually that was not needed since I could have them through the interfaces from GeoAPI.

I appreciate your help, I could not have resolved this

roji commented 5 years ago

Great. Note that it's fine to reference NetTopologySuite directly and used the classes rather than the geoapi interfaces. The issue was that you were referencing the wrong version.

auspex commented 5 years ago

Could you explain a little more, please? @pierrosv said he was using NetTopologySuite 2.0.0, and it seems to me like he should be. Since I'm having the same problem, I really need to know what I should be using. My packages are listed below—I have my doubts about that NetTopologySuite.Core

$ dotnet list package --include-transitive
Project 'uk.ac.sahfos.cpr.console.web' has the following package references
   [netcoreapp2.2]: 
   Top-level Package                                                  Requested   Resolved
   > BuildBundlerMinifier                                             2.6.362     2.6.362 
   > Grid.AspNetCore.Mvc                                              1.0.0       1.0.0   
   > HtmlAgilityPack                                                  1.11.16     1.11.16 
   > Humanizer                                                        2.6.2       2.6.2   
   > Microsoft.AspNetCore.All                                   (A)   [2.2.0, )   2.2.0   
   > Microsoft.EntityFrameworkCore.Design                             2.2.4       2.2.4   
   > Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite         2.2.6       2.2.6   
   > Microsoft.Extensions.Caching.Memory                              2.2.0       2.2.0   
   > Microsoft.Extensions.Logging.Debug                               2.2.0       2.2.0   
   > Microsoft.NETCore.App                                      (A)   [2.2.0, )   2.2.0   
   > Microsoft.VisualStudio.Web.BrowserLink                           2.2.0       2.2.0   
   > Microsoft.VisualStudio.Web.CodeGeneration.Design                 2.2.0       2.2.0   
   > NetTopologySuite                                                 2.0.0       2.0.0   
   > Novell.Directory.Ldap.NETStandard                                2.3.8       2.3.8   
   > Npgsql.EntityFrameworkCore.PostgreSQL                            2.2.4       2.2.4   
   > Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite           2.2.4       2.2.4   

   Transitive Package                                                                   Resolved
   > GeoAPI.Core                                                                        1.7.5   
   ...
   > Microsoft.AspNetCore                                                               2.2.0   
   ...
   > Microsoft.EntityFrameworkCore                                                      2.2.6   
   ...
   > NetTopologySuite.Core                                                              1.15.1  
   > NetTopologySuite.IO.PostGis                                                        1.15.0  
   > NetTopologySuite.IO.SqlServerBytes                                                 1.15.0  
   > Npgsql                                                                             4.0.7   
   > Npgsql.NetTopologySuite                                                            4.0.4.1 
roji commented 5 years ago

The following combinations are OK:

Your dependency graph shows Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite 2.2.4 being used with NetTopologySuite 2.0.0, which won't work. Remove your explicit reference to NetTopologySuite 2.0.0 and let nuget resolve the version (which will be 1.x).

auspex commented 5 years ago

Thanks!