Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to insert/get EMPTY geometry (Polygon.Empty or similar), throwing error #3467

Closed
manish-sh opened this issue Jan 20, 2021 · 5 comments
Assignees
Labels
Milestone

Comments

@manish-sh
Copy link

manish-sh commented Jan 20, 2021

Database has a column with type geometry (nullable). We are facing error when trying to insert Empty geometry, or try to get same from DB.
Error (when try to insert):
Message: XX000: WKB structure does not match expected size!

Sample Code:

var resource = new Resource
{
    Name = "Test1",
    Status = "added",
    Geometry = Polygon.Empty
};
resourceRepository.Insert(resource);
await resourceRepository.SaveChanges();

Stacktrace:

   at Npgsql.NpgsqlConnector.<<ReadMessage>g__ReadMessageLong|194_0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Npgsql.NpgsqlDataReader.<NextResult>d__44.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__105.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__105.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlCommand.<ExecuteDbDataReaderAsync>d__98.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__29.MoveNext()

Error (When try to get):

Message: Unable to read beyond the end of the stream.

Data in Geometry column: '010300000000000000' (Generated via ST_GeomFromText('POLYGON EMPTY'))

Stack trace:
   at System.IO.BinaryReader.InternalRead(Int32 numBytes)
   at System.IO.BinaryReader.ReadInt32()
   at NetTopologySuite.IO.BiEndianBinaryReader.ReadInt32()
   at NetTopologySuite.IO.PostGisReader.ReadCoordinateSequence(BinaryReader reader, CoordinateSequenceFactory factory, PrecisionModel precisionModel, Ordinates receivedOrdinates)
   at NetTopologySuite.IO.PostGisReader.ReadLinearRing(BinaryReader reader, GeometryFactory factory, Ordinates ordinates)
   at NetTopologySuite.IO.PostGisReader.ReadPolygon(BinaryReader reader, GeometryFactory factory, Ordinates ordinates)
   at NetTopologySuite.IO.PostGisReader.Read(BinaryReader reader)
   at NetTopologySuite.IO.PostGisReader.Read(Stream stream)
   at Npgsql.NetTopologySuite.NetTopologySuiteHandler.ReadCore[T](NpgsqlReadBuffer buf, Int32 len)
   at Npgsql.NetTopologySuite.NetTopologySuiteHandler.Read(NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription)
   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.<ReadAsObject>d__8.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlDataReader.GetValue(Int32 ordinal)
   at Npgsql.NpgsqlDataReader.GetValues(Object[] values)
   at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
   at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
   at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
   at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at TestApp.Program.<SpatialDataTypeTest>d__3.MoveNext() in C:\Users\manish.s\Source\Repos\TestApp\Program.cs:line 52

Please let me know if needed more details.

@YohDeadfall
Copy link
Contributor

Which version of EF are you using?

@manish-sh
Copy link
Author

manish-sh commented Jan 20, 2021

Which version of EF are you using?

Using Microsoft.EntityFrameworkCore, version 5.0.2. Faced the issue in version 3.1.9 , and updated to check if still exists.
Current Npgsql libraries are also 5.0.1 .

@roji
Copy link
Member

roji commented Jan 20, 2021

I can see an issue, will investigate.

@roji
Copy link
Member

roji commented Jan 20, 2021

Note: opened NetTopologySuite/NetTopologySuite.IO.PostGis#14 as this seems to be an issue there.

@roji
Copy link
Member

roji commented May 10, 2021

Fixed in main via 3930532
Backported to 5.0.5 via bf4e949

@roji roji closed this as completed May 10, 2021
@roji roji removed the blocked label May 10, 2021
@roji roji self-assigned this May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants