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<T> from a SingleQueryingEnumerable — the standard query enumerable for non-split relational queries. The enumerator wraps a single DbDataReader that is consumed once and cannot be rewound, so Reset() throws NotSupportedException as permitted by the IEnumerator contract.
Solutions
- Do not call Reset(); re-execute the LINQ query for a fresh enumeration.
- Materialize with ToList()/ToListAsync() if multiple passes are needed.
- Report the Reset() call to the library or framework that makes it.
Example fix
// before using var e = context.Blogs.Where(b => b.Active).GetEnumerator(); e.Reset(); // throws // after var blogs = context.Blogs.Where(b => b.Active).ToList();
Defensive patterns
Strategy: validation
Prevention
- Never call Reset() on EF Core query enumerators — re-execute the query for fresh results.
- Materialize results with ToList()/ToListAsync() before passing to libraries or data-binding frameworks.
- Document that EF enumerators are forward-only in your codebase.
When it happens
Trigger: Calling .Reset() on the enumerator obtained from any standard LINQ-to-Entities query's GetEnumerator() (single-query mode). This is usually triggered by library code, not direct application code.
Common situations: A collection adapter, testing mock framework, or UI data binding component that calls Reset() on enumerators. Attempting to enumerate a query result twice with the same enumerator handle.
Related errors
- This enumerator cannot be reset.
- This enumerator cannot be reset.
- This enumerator cannot be reset.
- This enumerator cannot be reset.
- This enumerator cannot be reset.
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/bf62064123587e5d.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs:296
enumerator._relationalQueryContext.InitializeStateManager(enumerator._standAloneStateManager);
return false;
}
public void Dispose()
{
if (_dataReader is not null)
{
_relationalQueryContext.Connection.ReturnCommand(_relationalCommand!);
_dataReader.Dispose();
_dataReader = null;
_dbDataReader = null;
}
}
public void Reset()
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
}
private sealed class AsyncEnumerator : IAsyncEnumerator<T>
{
private readonly RelationalQueryContext _relationalQueryContext;
private readonly RelationalCommandResolver _relationalCommandResolver;
private readonly IReadOnlyList<ReaderColumn?>? _readerColumns;
private readonly Func<QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator, T> _shaper;
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;
private readonly CancellationToken _cancellationToken;
private IRelationalCommand? _relationalCommand;
private RelationalDataReader? _dataReader;View on GitHub (pinned to 3a2006ef56)