Skip to content

Commit 6c3273e

Browse files
committed
Fix NullReferenceException when reader is disposed.
1 parent c25ef03 commit 6c3273e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ public sealed class MySqlDataReader : DbDataReader
2121
{
2222
public override bool NextResult()
2323
{
24-
Command.ResetCommandTimeout();
24+
Command?.ResetCommandTimeout();
2525
return NextResultAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
2626
}
2727

2828
public override bool Read()
2929
{
30-
Command.ResetCommandTimeout();
30+
Command?.ResetCommandTimeout();
3131
return GetResultSet().Read();
3232
}
3333

3434
public override Task<bool> ReadAsync(CancellationToken cancellationToken)
3535
{
36-
Command.ResetCommandTimeout();
36+
Command?.ResetCommandTimeout();
3737
return GetResultSet().ReadAsync(cancellationToken);
3838
}
3939

@@ -433,7 +433,7 @@ private void DoClose()
433433
private void VerifyNotDisposed()
434434
{
435435
if (Command == null)
436-
throw new ObjectDisposedException(GetType().Name);
436+
throw new InvalidOperationException("Can't call this method when MySqlDataReader is closed.");
437437
}
438438

439439
private ResultSet GetResultSet()

0 commit comments

Comments
 (0)