Search code examples
c#sql-serverentity-framework-corenettopologysuite

Entity Framework Core IndexOutOfRangeException when saving geometry using NetTopologySuite


I'm getting a DbUpdateException when I call SaveChanges with some geometries loaded from a shapefile. The error I get is:

IndexOutOfRangeException: Index was outside the bounds of the array.

Here is some sample code that saves two WKT polygons: the first is fine but the second generates the error:

https://gist.github.com/capesean/57527a0576d5972ff1514438440397fa

(The WKT code is too long to paste here)

The WKT seems valid: http://dev.openlayers.org/examples/vector-formats.html

And I can load it straight into SQL Server:

INSERT INTO regions 
VALUES (NEWID(), 'POLYGON ((30.613919943000042 -30.391359940999962, ......))')

Solution

  • This is a limitation to the TdsParser of SqlClient. Se the issue here: https://github.com/aspnet/EntityFrameworkCore/issues/18813