{"record":{"id":"d1dcf03f301de296","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-drawingcollection","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/DrawingCollection.cs","lineNumber":884,"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 Drawing 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 Drawing _current;\n            private DrawingCollection _list;\n            private uint _version;\n            private int _index;\n            #endregion\n        }","sourceCodeStart":866,"sourceCodeEnd":902,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/DrawingCollection.cs#L866-L902","documentation":"DrawingCollection's Enumerator.Current throws InvalidOperationException (SR.Enumerator_NotStarted) when accessed while _index == -1, i.e. before the first MoveNext call. Current is only valid between a successful MoveNext and the next step/past-the-end.","triggerScenarios":"Reading enumerator.Current (or accessing Current via manual enumerator code) immediately after GetEnumerator() without calling MoveNext().","commonSituations":"Hand-rolled enumerator loops that read Current before stepping; generic helper code assuming Current has a default value like .NET's IEnumerator contract differences.","solutions":["Call MoveNext() and check its return value before reading Current.","Prefer foreach, which handles the protocol for you.","If lazily reading current items, initialize with if (e.MoveNext()) { var d = e.Current; }."],"exampleFix":"// before\nvar e = collection.GetEnumerator(); var first = e.Current; // throws\n// after\nvar e = collection.GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"validation","validationCode":"if (e.MoveNext()) { var current = e.Current; }","typeGuard":"null","tryCatchPattern":"try { var c = e.Current; } catch (InvalidOperationException) { /* enumerator not started: call MoveNext first */ }","preventionTips":["Always call MoveNext() and check its result before reading Current","Prefer foreach which enforces the protocol","Do not cache enumerators across call boundaries"],"tags":["wpf","enumerator","invalid-state"],"backgroundTag":"enumerator-not-started","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"}