From 4eab8ec00bbd84c2a397ad6f6e1c7e0888d5790d Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 30 Sep 2021 00:56:24 +0100 Subject: [PATCH] add reliability section aronud internal read shortcut for netfx --- .../Microsoft/Data/SqlClient/SqlDataReader.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs index eacc2d3ed5..d330ba964a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs @@ -4393,7 +4393,7 @@ out dataLength } else { - Debug.Assert(false, "we have read past the column somehow, this is an error"); + //Debug.Assert(false, "we have read past the column somehow, this is an error"); } } else @@ -5691,9 +5691,25 @@ private static Task GetFieldValueAsyncExecute(Task task, object state) if (typeof(T) == typeof(Stream) || typeof(T) == typeof(TextReader) || typeof(T) == typeof(XmlReader)) { - if (reader.IsCommandBehavior(CommandBehavior.SequentialAccess) && reader._sharedState._dataReady && reader.TryReadColumnInternal(context._columnIndex, readHeaderOnly: true, forStreaming: false)) + if (reader.IsCommandBehavior(CommandBehavior.SequentialAccess) && reader._sharedState._dataReady) { - return Task.FromResult(reader.GetFieldValueFromSqlBufferInternal(reader._data[columnIndex], reader._metaData[columnIndex], isAsync: true)); + bool internalReadSuccess = false; + TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); + RuntimeHelpers.PrepareConstrainedRegions(); + try + { + tdsReliabilitySection.Start(); + internalReadSuccess = reader.TryReadColumnInternal(context._columnIndex, readHeaderOnly: true, forStreaming: false); + } + finally + { + tdsReliabilitySection.Stop(); + } + + if (internalReadSuccess) + { + return Task.FromResult(reader.GetFieldValueFromSqlBufferInternal(reader._data[columnIndex], reader._metaData[columnIndex], isAsync: true)); + } } }