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

Fix NullReferenceException in GetBytesAsync #1906

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5285,7 +5285,7 @@ protected override void DisposeCore()
{
TDisposable copy = _disposable;
_disposable = default;
copy.Dispose();
copy?.Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
Expand Down Expand Up @@ -471,6 +472,37 @@ public static void InvalidCastExceptionStream(CommandBehavior behavior, Accessor
}
}

#if NETCOREAPP
[ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static async void ReadAsyncContentsCompletes()
{
string expectedXml = "<test>This is a test string</test>";
string query = $"SELECT CAST('{expectedXml}' AS NVARCHAR(MAX))";

string returnedXml = null;
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();

await using (SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess).ConfigureAwait(false))
{
while (await reader.ReadAsync().ConfigureAwait(false))
{
using (TextReader textReader = reader.GetTextReader(0))
using (XmlReader xmlReader = XmlReader.Create(textReader, new XmlReaderSettings() { Async = true }))
{
XDocument xdoc = await XDocument.LoadAsync(xmlReader, LoadOptions.None, default).ConfigureAwait(false);
returnedXml = xdoc.ToString();
}
}
}
}

Assert.Equal(expectedXml, returnedXml, StringComparer.Ordinal);
}
#endif

private static async Task<SqlDataReader> ExecuteReader(SqlCommand command, CommandBehavior behavior, bool isExecuteAsync)
=> isExecuteAsync ? await command.ExecuteReaderAsync(behavior) : command.ExecuteReader(behavior);

Expand Down