dotnet/wpf · error · InvalidOperationException
SR.Enumerator_NotStarted
Error message
SR.Enumerator_NotStarted
What it means
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.
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
Example fix
// before
var e = xmlLanguage.GetMatchingLanguages().GetEnumerator();
var first = e.Current; // throws
// after
var e = xmlLanguage.GetMatchingLanguages().GetEnumerator();
if (e.MoveNext()) { var first = e.Current; } Defensive patterns
Strategy: try-catch
Validate before calling
var e = xmlLanguage.GetMatchingLanguages().GetEnumerator(); bool started = e.MoveNext(); if (!started) return; // empty: skip Current access
Try / catch
try { var first = e.Current; } catch (InvalidOperationException) { /* not started */ } Prevention
- Prefer foreach over manual enumerators
- Never read Current before a successful MoveNext
When it happens
Trigger: 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.
Common situations: Hand-written loops over the language fallback list instead of foreach; porting code that assumed Current returns the first element before iteration starts.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.Enumerator_CollectionChanged
- SR.Enumerator_NotStarted
- SR.Enumerator_NotStarted
- SR.Enumerator_ReachedEnd
- SR.Enumerator_ReachedEnd
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e4c57557a56bbc85.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs:519
_atStart = true;
_maxCultureDepth = XmlLanguage.MaxCultureDepth;
}
public void Reset()
{
_current = _start;
_pastEnd = false;
_atStart = true;
_maxCultureDepth = XmlLanguage.MaxCultureDepth;
}
public XmlLanguage Current
{
get
{
if (_atStart)
{
throw new InvalidOperationException(SR.Enumerator_NotStarted);
}
if (_pastEnd)
{
throw new InvalidOperationException(SR.Enumerator_ReachedEnd);
}
return _current;
}
}
public bool MoveNext()
{
if (_atStart)
{
_atStart = false;
return true;
}
else if (_current.IetfLanguageTag.Length == 0)View on GitHub (pinned to 81131a70a4)