{"record":{"id":"6548d620b6b86efe","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-doublecollection","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/DoubleCollection.cs","lineNumber":867,"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 double 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 double _current;\n            private DoubleCollection _list;\n            private uint _version;\n            private int _index;\n            #endregion\n        }","sourceCodeStart":849,"sourceCodeEnd":885,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DoubleCollection.cs#L849-L885","documentation":"The DoubleCollection enumerator's Current property throws InvalidOperationException with SR.Enumerator_NotStarted when accessed before the first MoveNext call. _index is still -1 (positioned before the first element), so there is no valid current element to return.","triggerScenarios":"Getting an enumerator from a DoubleCollection and reading Current (or using foreach's current variable manually) before calling MoveNext() the first time.","commonSituations":"Manual IEnumerator loops where Current is read before MoveNext; enumerator positioned and inspected in a debugger/property evaluator that touches Current; hand-rolled iteration code skipping the initial MoveNext.","solutions":["Call MoveNext() at least once before reading Current.","Structure iteration as while (enumerator.MoveNext()) { use enumerator.Current; }.","Use a foreach loop, which always calls MoveNext before exposing the element."],"exampleFix":"// before\nvar e = coll.GetEnumerator();\nvar d = e.Current; // InvalidOperationException: Enumerator_NotStarted\n// after\nvar e = coll.GetEnumerator();\nwhile (e.MoveNext()) { var d = e.Current; }","handlingStrategy":"type-guard","validationCode":"// track MoveNext state before touching Current\nbool started = false;\n// call MoveNext() at least once before reading Current","typeGuard":"static T? SafeCurrent<T>(IEnumerator<T> e) where T : struct => e.MoveNext() ? e.Current : default; // wrap with started-flag logic","tryCatchPattern":"try { var d = e.Current; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Enumerator_NotStarted\"))\n{ if (e.MoveNext()) { var d = e.Current; } }","preventionTips":["Always gate Current access on a successful MoveNext().","Prefer foreach over manual enumerator handling.","Never inspect Current in debugger-watch or property contexts before starting iteration."],"tags":["wpf","enumerator","current","invalid-state"],"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"}