{"record":{"id":"1a9552293cb405e3","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-pathsegmentcollection","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/PathSegmentCollection.cs","lineNumber":849,"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 PathSegment 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 PathSegment _current;\n            private PathSegmentCollection _list;\n            private uint _version;\n            private int _index;\n            #endregion\n        }","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathSegmentCollection.cs#L831-L867","documentation":"PathSegmentCollection's Enumerator.Current throws Enumerator_NotStarted (InvalidOperationException) when Current is accessed before the first MoveNext call. The enumerator's index is still -1 (before the first element), so there is no valid current item.","triggerScenarios":"Reading the Enumerator.Current property immediately after GetEnumerator() without calling MoveNext() first.","commonSituations":"Manual enumerator code that forgets the initial MoveNext, or UI/update logic that reads Current outside a proper iteration loop.","solutions":["Call MoveNext() and check it returned true before reading Current.","Use foreach, which handles the MoveNext contract automatically.","Initialize/enumerate the iterator before exposing Current to other code.","Guard reads of Current with a check that at least one MoveNext succeeded."],"exampleFix":"// before\nvar e = segments.GetEnumerator();\nvar first = e.Current; // throws\n// after\nvar e = segments.GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"validation","validationCode":"if (!e.MoveNext()) return; // no elements; only read Current after MoveNext()==true","typeGuard":null,"tryCatchPattern":"try { var cur = e.Current; }\ncatch (InvalidOperationException) { /* Current accessed before start */ }","preventionTips":["Always gate Current access on a successful MoveNext","Use foreach instead of manual enumerators","Never expose raw enumerators' Current without MoveNext contract"],"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"}