dotnet/efcore · error · NotSupportedException

This enumerator cannot be reset.

Error message

This enumerator cannot be reset.

What it means

Thrown when calling Reset() on the IEnumerator returned by a GroupBy query using split-query mode (AsSplitQuery()). Split query enumerators manage multiple DbDataReaders and a result coordinator; they are inherently forward-only and cannot be rewound. Reset() throws NotSupportedException per IEnumerator conventions.

Solutions

  1. Do not call Reset(); re-execute the GroupBy split query for fresh results.
  2. Call ToList()/ToListAsync() to materialize before passing results to code that may reset.
  3. Report the Reset() usage to the library/framework that triggers it.

Example fix

// before
using var e = context.Orders
    .AsSplitQuery()
    .GroupBy(o => o.CustomerId)
    .GetEnumerator();
e.Reset(); // throws

// after
var groups = context.Orders
    .AsSplitQuery()
    .GroupBy(o => o.CustomerId)
    .ToList();
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Calling .Reset() on the enumerator of a GroupBy query executed with UseSplitQuery() or AsSplitQuery(). The enumerator manages multiple data readers for separate round-trips, making rewind impossible.

Common situations: Library or test framework code that generically calls Reset() on any IEnumerator. Attempting to re-enumerate split-query results without re-running the query.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/0925bec5ff067988. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Query/Internal/GroupBySplitQueryingEnumerable.cs:383

                if (_resultCoordinator != null)
                {
                    foreach (var dataReader in _resultCoordinator.DataReaders)
                    {
                        dataReader?.DataReader.Dispose();
                    }

                    _resultCoordinator.DataReaders.Clear();

                    _resultCoordinator = null;
                }

                _dataReader = null;
                _dbDataReader = null;
            }
        }

        public void Reset()
            => throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
    }

    private sealed class AsyncEnumerator : IAsyncEnumerator<IGrouping<TKey, TElement>>
    {
        private readonly RelationalQueryContext _relationalQueryContext;
        private readonly RelationalCommandResolver _relationalCommandResolver;
        private readonly IReadOnlyList<ReaderColumn?>? _readerColumns;
        private readonly Func<QueryContext, DbDataReader, TKey> _keySelector;
        private readonly Func<QueryContext, DbDataReader, object[]> _keyIdentifier;
        private readonly IReadOnlyList<Func<object, object, bool>> _keyIdentifierValueComparers;
        private readonly Func<QueryContext, DbDataReader, ResultContext, SplitQueryResultCoordinator, TElement> _elementSelector;
        private readonly Func<QueryContext, IExecutionStrategy, SplitQueryResultCoordinator, Task>? _relatedDataLoaders;
        private readonly Type _contextType;
        private readonly IDiagnosticsLogger<DbLoggerCategory.Query> _queryLogger;
        private readonly bool _standAloneStateManager;
        private readonly bool _detailedErrorsEnabled;
        private readonly IConcurrencyDetector? _concurrencyDetector;
        private readonly IExceptionDetector _exceptionDetector;

View on GitHub (pinned to 3a2006ef56)