From 68b0bb1730c27cb6b6069d3fff4db099cbf679e1 Mon Sep 17 00:00:00 2001 From: Joe Amenta Date: Mon, 15 Apr 2024 08:46:20 -0400 Subject: [PATCH] Fix an oversight where the original exception message would get replaced by this other one in many cases. --- .../Converters/Utility.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/NetTopologySuite.IO.GeoJSON4STJ/Converters/Utility.cs b/src/NetTopologySuite.IO.GeoJSON4STJ/Converters/Utility.cs index 97180ce..52829e0 100644 --- a/src/NetTopologySuite.IO.GeoJSON4STJ/Converters/Utility.cs +++ b/src/NetTopologySuite.IO.GeoJSON4STJ/Converters/Utility.cs @@ -1,6 +1,8 @@ using System; +using System.Buffers; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Text; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; @@ -93,6 +95,13 @@ private static void ThrowForUnexpectedEndOfStream() [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowForUnexpectedToken(JsonTokenType requiredNextTokenType, ref Utf8JsonReader reader) - => throw new JsonException(string.Format(Resources.EX_UnexpectedToken, requiredNextTokenType, reader.TokenType, reader.GetString())); + => throw new JsonException(string.Format(Resources.EX_UnexpectedToken, requiredNextTokenType, reader.TokenType, CurrentTokenAsString(in reader))); + + private static string CurrentTokenAsString(in Utf8JsonReader reader) + { + return Encoding.UTF8.GetString(reader.HasValueSequence + ? reader.ValueSequence.ToArray() + : reader.ValueSpan.ToArray()); + } } }