{"record":{"id":"073dedc50946aae3","repo":"dotnet/wpf","slug":"sr-enumerator-reachedend-xmllanguage","errorCode":null,"errorMessage":"SR.Enumerator_ReachedEnd","messagePattern":"SR\\.Enumerator_ReachedEnd","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs","lineNumber":523,"sourceCode":"            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)\n                {\n                    _atStart = false;\n                    _pastEnd = true;\n                    return false;","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs#L505-L541","documentation":"Reading Current on a MatchingLanguageEnumerator after MoveNext() returned false, i.e. iteration has passed the last element. The enumerator throws InvalidOperationException because there is no current item to return.","triggerScenarios":"Calling Current after MoveNext() returned false; repeatedly reading Current in a loop that ignores MoveNext's return value; re-reading Current at the end of manual iteration.","commonSituations":"Manual while(true) loops over GetMatchingLanguages() without breaking on false; enumerators stored across iterations and advanced past the end.","solutions":["Break out of the loop when MoveNext() returns false before touching Current","Use foreach, which never reads Current past the end","Reset or re-acquire the enumerator instead of continuing to advance it"],"exampleFix":"// before\nwhile (true) { Process(e.Current); e.MoveNext(); } // throws at end\n// after\nwhile (e.MoveNext()) { Process(e.Current); }","handlingStrategy":"try-catch","validationCode":"bool hasCurrent = e.MoveNext();\n// only then read e.Current","typeGuard":null,"tryCatchPattern":"try { var v = e.Current; } catch (InvalidOperationException) { /* past end */ }","preventionTips":["Break loops when MoveNext() returns false","Use foreach which guarantees Current is valid"],"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"}