{"record":{"id":"766fd36c8288ddc1","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-pathfigurecollection","errorCode":null,"errorMessage":"SR.Enumerator_NotStarted","messagePattern":"SR\\.Enumerator_NotStarted","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollection.cs","lineNumber":939,"sourceCode":"            /// <summary>\n            /// Current element\n            ///\n            /// The behavior of IEnumerable&lt;T>.Current is undefined\n            /// before the first MoveNext and after we have walked\n            /// off the end of the list. However, the IEnumerable.Current\n            /// contract requires that we throw exceptions\n            /// </summary>\n            public PathFigure Current\n            {\n                get\n                {\n                    if (_index > -1)\n                    {\n                        return _current;\n                    }\n                    else if (_index == -1)\n                    {\n                        throw new InvalidOperationException(SR.Enumerator_NotStarted);\n                    }\n                    else\n                    {\n                        Debug.Assert(_index == -2, \"expected -2, got \" + _index + \"\\n\");\n                        throw new InvalidOperationException(SR.Enumerator_ReachedEnd);\n                    }\n                }\n            }\n\n            #endregion\n\n            #region Data\n            private PathFigure _current;\n            private PathFigureCollection _list;\n            private uint _version;\n            private int _index;\n            #endregion\n        }","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollection.cs#L921-L957","documentation":"PathFigureCollection.Enumerator.Current throws InvalidOperationException with SR.Enumerator_NotStarted when Current is read before the first call to MoveNext(). The enumerator uses _index == -1 to mean 'not started' and refuses to return a Current value in that state.","triggerScenarios":"Accessing the Current property of a PathFigureCollection enumerator immediately after GetEnumerator() without calling MoveNext() first.","commonSituations":"Hand-written enumerator loops that forget the initial MoveNext; code that stores an enumerator and reads Current speculatively; misused LINQ replacements or manual foreach expansions.","solutions":["Call MoveNext() at least once before reading Current.","Use a foreach loop instead of manual enumerator handling so the protocol is enforced.","Reset the enumerator (or get a new one) if it was consumed and you need to iterate again."],"exampleFix":"// before\nvar e = figures.GetEnumerator();\nvar first = e.Current;\n// after\nvar e = figures.GetEnumerator();\nif (e.MoveNext())\n{\n    var first = e.Current;\n}","handlingStrategy":"type-guard","validationCode":"var e = figures.GetEnumerator();\nif (!e.MoveNext()) return; // empty collection\nProcessCurrent(e.Current);","typeGuard":"bool TryGetFirst(PathFigureCollection c, out PathFigure first)\n{\n    var e = c.GetEnumerator();\n    if (e.MoveNext()) { first = e.Current; return true; }\n    first = null; return false;\n}","tryCatchPattern":"try\n{\n    var value = enumerator.Current;\n}\ncatch (InvalidOperationException)\n{\n    // enumerator not started; call MoveNext() first\n}","preventionTips":["Prefer foreach over manual enumerator protocols.","Always pair the first Current read with a successful MoveNext()."],"tags":["wpf","enumerator","invalid-operation"],"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"}