{"record":{"id":"9d519c9c7c936f49","repo":"dotnet/wpf","slug":"sr-enumeratornotstarted","errorCode":null,"errorMessage":"SR.EnumeratorNotStarted","messagePattern":"SR\\.EnumeratorNotStarted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ContentElementCollection.cs","lineNumber":343,"sourceCode":"                    return (true);\n                }\n                else\n                {\n                    _currentElement = _collection;\n                    _index = _collection.Size;\n                    return (false);\n                }\n            }\n\n            public TItem Current\n            {\n                get\n                {\n                    if (_currentElement == _collection)\n                    {\n                        if (_index == -1)\n                        {\n                            throw new InvalidOperationException(SR.EnumeratorNotStarted);\n                        }\n                        else\n                        {\n                            throw new InvalidOperationException(SR.EnumeratorReachedEnd);\n                        }\n                    }\n                    return (TItem)_currentElement;\n                }\n            }\n\n            /// <summary>\n            ///     <see cref=\"IEnumerator.Current\"/>\n            /// </summary>\n            object IEnumerator.Current\n            {\n                get\n                {\n                    return this.Current;","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ContentElementCollection.cs#L325-L361","documentation":"The enumerator's Current property throws InvalidOperationException with SR.EnumeratorNotStarted when Current is read before the first MoveNext call (_index == -1). The sentinel _currentElement == _collection marks Current as not yet valid, and _index distinguishes 'not started' from 'past the end'.","triggerScenarios":"Accessing the enumerator's Current property (or IEnumerable<T>.Current via an interface) immediately after calling GetEnumerator(), before any MoveNext()/MoveNext() returning true.","commonSituations":"Hand-rolled iteration that reads Current once before the loop, a do/while loop that touches Current before advancing, or DI/logging code that inspects the 'current' item at enumerator creation.","solutions":["Call MoveNext() and check it returns true before reading Current","Use a foreach loop, which never reads Current before MoveNext succeeds","If Current may be read at any time, guard with a position check or snapshot the collection"],"exampleFix":"// before\nvar e = collection.GetEnumerator();\nvar first = ((IEnumerator)e).Current;\n// after\nvar e = collection.GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"object current = null; if (enumerator.MoveNext()) { current = enumerator.Current; } else { /* handle empty/start state */ }","preventionTips":["Always call MoveNext() before reading Current","Prefer foreach over manual enumerator usage","Do not read Current immediately after GetEnumerator()"],"tags":["enumerator-state","wpf","collections"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}