{"record":{"id":"83f0f6ae32ab644d","repo":"dotnet/efcore","slug":"this-enumerator-cannot-be-reset-83f0f6","errorCode":null,"errorMessage":"This enumerator cannot be reset.","messagePattern":"This enumerator cannot be reset\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs","lineNumber":164,"sourceCode":"                return hasNext;\n            }\n\n            public void Dispose()\n            {\n                _enumerator?.Dispose();\n                _enumerator = null;\n            }\n\n            public ValueTask DisposeAsync()\n            {\n                var enumerator = _enumerator;\n                _enumerator = null;\n\n                return enumerator.DisposeAsyncIfAvailable();\n            }\n\n            public void Reset()\n                => throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);\n        }\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":168,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs#L146-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"Code that reuses an enumerator across multiple passes and calls Reset(), or third-party helpers that assume Reset() works. Rare in normal foreach usage.","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."],"exampleFix":"// before\nvar e = query.GetEnumerator();\nwhile (e.MoveNext()) { /* pass 1 */ }\ne.Reset();\nwhile (e.MoveNext()) { /* pass 2 */ }\n// after\nvar list = query.ToList();\nforeach (var x in list) { /* pass 1 */ }\nforeach (var x in list) { /* pass 2 */ }","handlingStrategy":"validation","validationCode":"// Never call Reset() on an EF query enumerator. Re-run the query or materialise:\nvar materialised = query.ToList(); // safe to enumerate multiple times","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","in-memory-provider","enumerator","notsupported"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}