Skip to content

InvalidOperationException thrown when RelationalDataReader reads RecordsAffected #1122

Description

@Executor-Cheng

Software versions
MySqlConnector version: 2.1.3
Server type (MySQL, MariaDB, Aurora, etc.) and version: MariaDB 10.5.5
.NET version: 6.0.0
Microsoft.EntityFrameworkCore version: 6.0.0
Pomelo.EntityFrameworkCore.MySql version: 6.0.0

Describe the bug
When the query fetches rows from the database, it will throw InvalidOperationException.

Exception

fail: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48]
      An error occurred while reading the key ring.
      System.InvalidOperationException: Can't call this method when MySqlDataReader is closed.
         at MySqlConnector.MySqlDataReader.VerifyNotDisposed() in /_/src/MySqlConnector/MySqlDataReader.cs:line 653
         at MySqlConnector.MySqlDataReader.GetResultSet() in /_/src/MySqlConnector/MySqlDataReader.cs:line 658
         at MySqlConnector.MySqlDataReader.get_RecordsAffected() in /_/src/MySqlConnector/MySqlDataReader.cs:line 205
         at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Dispose()
         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.Dispose()
         at Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.EntityFrameworkCoreXmlRepository`1.<GetAllElements>g__GetAllElementsCore|3_0()+MoveNext()
         at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
         at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
         at Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.EntityFrameworkCoreXmlRepository`1.GetAllElements()
         at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys()
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
         at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh)
System.InvalidOperationException: Can't call this method when MySqlDataReader is closed.
         at MySqlConnector.MySqlDataReader.VerifyNotDisposed() in /_/src/MySqlConnector/MySqlDataReader.cs:line 653
         at MySqlConnector.MySqlDataReader.GetResultSet() in /_/src/MySqlConnector/MySqlDataReader.cs:line 658
         at MySqlConnector.MySqlDataReader.get_RecordsAffected() in /_/src/MySqlConnector/MySqlDataReader.cs:line 205
         at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.DisposeAsync()
         at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.DisposeAsync()
         at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToArrayAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)

Code sample
await DbContext.Set<T>.FirstOrDefaultAsync();
await DbContext.Set<T>.ToArrayAsync();

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions