{"record":{"id":"8087086d2388d580","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-model3dcollection","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/Media3D/Generated/Model3DCollection.cs","lineNumber":882,"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 Model3D 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 Model3D _current;\n            private Model3DCollection _list;\n            private uint _version;\n            private int _index;\n            #endregion\n        }","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DCollection.cs#L864-L900","documentation":"Model3DCollection's enumerator Current property throws InvalidOperationException(SR.Enumerator_NotStarted) when accessed before the first MoveNext call (_index == -1). There is no valid 'current' element before iteration begins; accessing it early is a usage bug, not a data problem. (After the end, a different message, Enumerator_ReachedEnd, is thrown.)","triggerScenarios":"Reading enumerator.Current (or hitting it via foreach codegen misuse / manual enumerator loops) before calling MoveNext at least once; calling Current again after Reset without advancing.","commonSituations":"Hand-written enumerator loops with Current accessed outside the MoveNext loop condition; helper functions taking IEnumerator and peeking Current up front; after Reset() the state returns to -1 so an immediate Current read throws again.","solutions":["Always call MoveNext and check it returned true before reading Current.","Restructure to a foreach loop, which enforces correct Current access ordering.","If you need the first element without an enumerator, use collection[0] (after checking Count)."],"exampleFix":"// before\nvar e = collection.GetEnumerator();\nvar first = e.Current; // InvalidOperationException: not started\n// after\nvar e = collection.GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"validation","validationCode":"if (!e.MoveNext()) return; // no elements; only then read e.Current","typeGuard":"bool HasCurrent(IEnumerator e) { try { return e.MoveNext(); } catch { return false; } }","tryCatchPattern":"try { var cur = e.Current; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"NotStarted\")) { /* MoveNext was not called yet */ }","preventionTips":["Always call MoveNext before reading Current","Prefer foreach over manual enumerator use","Read the first element via collection[0] with a Count check when no iteration is needed"],"tags":["wpf","collection","enumerator"],"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"}