{"record":{"id":"34aadaa2bc6e2f25","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-generaltransformcollection","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/GeneralTransformCollection.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 GeneralTransform 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 GeneralTransform _current;\n            private GeneralTransformCollection _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/GeneralTransformCollection.cs#L831-L867","documentation":"GeneralTransformCollection.Enumerator.Current throws this InvalidOperationException when accessed before enumeration has started (internal _index is still -1, i.e. MoveNext() has never been called or Reset() was just called). The non-generic IEnumerator.Current contract requires an exception in this state instead of returning an undefined value.","triggerScenarios":"Accessing Current (or the explicit IEnumerator.Current) on a fresh enumerator from GeneralTransformCollection.GetEnumerator() without calling MoveNext() first, or accessing it immediately after calling Reset().","commonSituations":"Hand-written enumerator loops that read e.Current before the first e.MoveNext(); Reset()-then-Current patterns ported from code that assumed Current returns the first element; generic reflection/serialization helpers that poke at Current unconditionally.","solutions":["Call MoveNext() at least once and only read Current when it returns true.","Prefer a foreach loop, which manages MoveNext/Current ordering correctly.","If using Reset(), re-issue MoveNext() before touching Current.","Capture the current item as the return of MoveNext-driven iteration into a local variable instead of re-reading Current later."],"exampleFix":"// before\nvar e = collection.GetEnumerator();\nvar first = e.Current; // throws: not started\n\n// after\nvar e = collection.GetEnumerator();\nif (e.MoveNext())\n{\n    var first = e.Current;\n}","handlingStrategy":"validation","validationCode":"// only read Current after a successful MoveNext\nif (enumerator.MoveNext()) { var current = enumerator.Current; }","typeGuard":"static bool TryGetCurrent<T>(this IEnumerator<T> e, out T current) { if (e.MoveNext()) { current = e.Current; return true; } current = default; return false; }","tryCatchPattern":"try { var v = enumerator.Current; }\ncatch (InvalidOperationException) { /* enumerator not started: call MoveNext() first */ }","preventionTips":["Read Current strictly inside a MoveNext()==true guard.","Prefer foreach over manual enumerator usage.","After Reset(), always MoveNext() before reading Current.","Store the item in a local during iteration instead of re-reading Current later."],"tags":["wpf","enumerator","ienumerable","invalidoperation"],"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"}