{"record":{"id":"f423f75ea04464ac","repo":"dotnet/efcore","slug":"this-enumerator-cannot-be-reset","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.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs","lineNumber":186,"sourceCode":"                    else\n                    {\n                        _queryLogger.QueryIterationFailed(_contextType, exception);\n                    }\n\n                    throw;\n                }\n            }\n\n            public ValueTask DisposeAsync()\n            {\n                _response = null;\n                _hasExecuted = false;\n\n                return default;\n            }\n\n            public void Reset()\n                => throw new NotSupportedException(CoreStrings.EnumerableResetNotSupported);\n\n            private bool ShapeResult()\n            {\n                var hasNext = _response is not null;\n\n                _cosmosQueryContext.InitializeStateManager(_standAloneStateManager);\n\n                Current\n                    = hasNext\n                        ? _shaper(_cosmosQueryContext, _response.Value, ordinal: 0, out _)\n                        : default;\n\n                _hasExecuted = true;\n\n                return hasNext;\n            }\n        }\n    }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs#L168-L204","documentation":"Thrown by Reset() on the ReadItem query enumerator. EF Core's Cosmos enumerators are forward-only, single-pass async enumerators that consume a network response stream; resetting and re-reading is not supported, so Reset throws NotSupportedException.","triggerScenarios":"Calling .Reset() on an IEnumerator obtained from a Cosmos query result. Typically indirect, via a library or LINQ operator that materializes enumerators and calls Reset.","commonSituations":"Interoperating with code that assumes resettable enumerators (rare). Custom wrappers around EF query results that call Reset. Misuse of enumerator semantics.","solutions":["Do not call Reset on EF Core Cosmos query enumerators; re-execute the query instead.","Cache the materialized result (e.g. ToListAsync) if you need to iterate multiple times.","Avoid enumerator-sharing patterns; consume the async enumerator once."],"exampleFix":"// before\nusing var e = query.GetAsyncEnumerator();\nwhile (e.MoveNextAsync().Result) { /* ... */ }\ne.Reset();\n// after\nvar list = await query.ToListAsync();\nforeach (var item in list) { /* iterate as many times as needed */ }","handlingStrategy":"validation","validationCode":"// Never reset; materialize once if multiple iterations are needed\nvar list = await query.ToListAsync();\n// iterate list freely; do not call Reset on any enumerator","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Reset on EF Core query enumerators.","Materialize with ToListAsync when you need multiple passes.","Avoid sharing enumerators across consumers."],"tags":["cosmos","enumerator","reset","query"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}