{"record":{"id":"e4c57557a56bbc85","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-xmllanguage","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/Markup/XmlLanguage.cs","lineNumber":519,"sourceCode":"                _atStart = true;\n                _maxCultureDepth = XmlLanguage.MaxCultureDepth;\n            }\n\n            public void Reset()\n            {\n                _current = _start;\n                _pastEnd = false;\n                _atStart = true;\n                _maxCultureDepth = XmlLanguage.MaxCultureDepth;\n            }\n\n            public XmlLanguage Current\n            {\n                get\n                {\n                    if (_atStart)\n                    {\n                        throw new InvalidOperationException(SR.Enumerator_NotStarted);\n                    }\n                    if (_pastEnd)\n                    {\n                        throw new InvalidOperationException(SR.Enumerator_ReachedEnd);\n                    }\n \n                    return _current;\n                }\n            }\n\n            public bool MoveNext()\n            {\n                if (_atStart)\n                {\n                    _atStart = false;\n                    return true;\n                }\n                else if (_current.IetfLanguageTag.Length == 0)","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs#L501-L537","documentation":"Calling Current on the MatchingLanguageEnumerator returned by XmlLanguage.GetMatchingLanguages().GetEnumerator() before MoveNext() was ever called. The WPF enumerator contract requires MoveNext() first; the library throws InvalidOperationException to signal the cursor is still at its initial position.","triggerScenarios":"Getting the enumerator from GetMatchingLanguages() and reading Current immediately without calling MoveNext(); using a cached enumerator after reset; manual iteration misuse that touches Current first.","commonSituations":"Hand-written loops over the language fallback list instead of foreach; porting code that assumed Current returns the first element before iteration starts.","solutions":["Call MoveNext() once and check its return value before reading Current","Use foreach (XmlLanguage lang in xmlLanguage.GetMatchingLanguages()) so the compiler-generated loop handles ordering","Guard with a boolean tracking whether MoveNext succeeded"],"exampleFix":"// before\nvar e = xmlLanguage.GetMatchingLanguages().GetEnumerator();\nvar first = e.Current; // throws\n// after\nvar e = xmlLanguage.GetMatchingLanguages().GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"try-catch","validationCode":"var e = xmlLanguage.GetMatchingLanguages().GetEnumerator();\nbool started = e.MoveNext();\nif (!started) return; // empty: skip Current access","typeGuard":null,"tryCatchPattern":"try { var first = e.Current; } catch (InvalidOperationException) { /* not started */ }","preventionTips":["Prefer foreach over manual enumerators","Never read Current before a successful MoveNext"],"tags":["wpf","enumerator","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"}