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

Error while reading multi-polygon from database #2594

Open
AZITWB opened this issue Aug 29, 2019 · 3 comments

Comments

@AZITWB
Copy link

commented Aug 29, 2019

Description

I got an error while reading multipolygonZ data type from database.

Steps to reproduce

Download source code:
https://github.com/npgsql/npgsql/releases/tag/v4.0.9

In soultion Npgsql, project Npgsql.PluginTests file LegacyPostgisTests.cs
add code bellow

[Test]
public void RoundtripMultipolygonZ()
{
	var multipolygon =
		@"MULTIPOLYGON (((538061.05 6140565.96,538064.36 6140569.1,538042.22 6140607.81,538039.32 6140605.66,538061.05 6140565.96)),((538062.05 6140565.96,538064.36 6140569.1,538042.22 6140607.81,538039.32 6140605.66,538062.05 6140565.96)))";
	using (var conn = OpenConnection())
	{
		conn.ExecuteNonQuery("CREATE TEMP TABLE data (geom geometry(MultiPolygonZ,25832))");
		using (var cmd = new NpgsqlCommand("INSERT INTO data (geom) VALUES (ST_Force3D(ST_GeomFromText('"+ multipolygon + "',25832)))", conn))
		{
			cmd.ExecuteNonQuery();
		}

		using (var cmd = new NpgsqlCommand("SELECT  geom FROM data", conn))
		using (var reader = cmd.ExecuteReader())
		{
			reader.Read();

			// This is the problem:
			var readMultipolygon = reader.GetValue(0);
		}
	}
}

The issue

Unable get MultiPolygon object from reader

Following error occurs :

System.OverflowException : Array dimensions exceeded supported range.
   at Npgsql.LegacyPostgis.LegacyPostgisHandler.<DoRead>d__1.MoveNext() in ..\NpqSQL\npgsql-4.0.9\src\Npgsql.LegacyPostgis\LegacyPostgisHandler.cs:line 150
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Npgsql.LegacyPostgis.LegacyPostgisHandler.<Read>d__0.MoveNext() in ..\NpqSQL\npgsql-4.0.9\src\Npgsql.LegacyPostgis\LegacyPostgisHandler.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.Read[TAny](NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription) in ..\NpqSQL\npgsql-4.0.9\src\Npgsql\TypeHandling\NpgsqlTypeHandler`.cs:line 114
   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.ReadAsObject(NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription) in ..\NpqSQL\npgsql-4.0.9\src\Npgsql\TypeHandling\NpgsqlTypeHandler`.cs:line 120
   at Npgsql.NpgsqlDefaultDataReader.GetValue(Int32 ordinal) in ..\NpqSQL\npgsql-4.0.9\src\Npgsql\NpgsqlDefaultDataReader.cs:line 139
   at Npgsql.PluginTests.LegacyPostgisTests.RoundtripMultipolygonZ() in ..\NpqSQL\npgsql-4.0.9\test\Npgsql.PluginTests\LegacyPostgisTests.cs:line 530

Further technical details

Npgsql version:4.0.9
PostgreSQL version: 9.6
Operating system: Windows 10

@roji

This comment has been minimized.

Copy link
Member

commented Aug 29, 2019

We'll try to take a look at this soon, but out of curiosity, is there any reason you're not using the newer spatial support based on NetTopologySuite?

@YohDeadfall YohDeadfall self-assigned this Aug 29, 2019

@AZITWB

This comment has been minimized.

Copy link
Author

commented Sep 3, 2019

There is no reason behind it. It was just first pick. It worked just fine for all of my cases except this one.

@roji

This comment has been minimized.

Copy link
Member

commented Sep 3, 2019

@AZITWB thanks for your answer. We'll still try to fix this as soon as possible, but in general NetTopologySuite is the better way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.