dotnet/efcore · error · NotSupportedException
This enumerator cannot be reset.
Error message
This enumerator cannot be reset.
What it means
Enumerator.Reset() in the InMemory QueryingEnumerable unconditionally throws NotSupportedException (CoreStrings.EnumerableResetNotSupported) (QueryingEnumerable.cs:163-164). EF Core query enumerators are single-pass; they cannot be rewound to the start.
Source
Thrown at src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs:164
return hasNext;
}
public void Dispose()
{
_enumerator?.Dispose();
_enumerator = null;
}
public ValueTask DisposeAsync()
{
var enumerator = _enumerator;
_enumerator = null;
return enumerator.DisposeAsyncIfAvailable();
}
public void Reset()
=> throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);
}
}
}
View on GitHub (pinned to dbf9771522)
Solutions
- Re-execute the query to obtain a fresh enumerator instead of calling Reset().
- Materialise results with ToList()/ToArray() and enumerate the in-memory collection multiple times.
- Wrap the query in a helper that returns a new enumerator on each request.
Example fix
// before
var e = query.GetEnumerator();
while (e.MoveNext()) { /* pass 1 */ }
e.Reset();
while (e.MoveNext()) { /* pass 2 */ }
// after
var list = query.ToList();
foreach (var x in list) { /* pass 1 */ }
foreach (var x in list) { /* pass 2 */ } Defensive patterns
Strategy: validation
Validate before calling
// Never call Reset() on an EF query enumerator. Re-run the query or materialise: var materialised = query.ToList(); // safe to enumerate multiple times
Prevention
- Treat EF query enumerators as single-pass; never call Reset().
- Materialise with ToList()/ToArray() if you need to iterate results more than once.
- Re-execute the query to start a fresh enumeration.
When it happens
Trigger: Calling Reset() on the IEnumerator<T> or IAsyncEnumerator<T> obtained from an EF Core InMemory LINQ query. Some LINQ-to-Objects helpers or custom iteration code invoke Reset.
Common situations: Code that reuses an enumerator across multiple passes and calls Reset(), or third-party helpers that assume Reset() works. Rare in normal foreach usage.
Related errors
- The LINQ expression '{expression}' could not be translated.
- Unable to translate set operation after client projection ha
- 'DefaultIfEmpty' cannot be applied after a client-evaluated
- Using 'Distinct' operation on a projection containing a subq
- The LINQ expression '{expression}' could not be translated.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/83f0f6ae32ab644d.
Report an issue: GitHub.