dotnet/wpf · error · InvalidOperationException
SR.Enumerator_NotStarted
Error message
SR.Enumerator_NotStarted
What it means
Point3DCollection's enumerator Current property throws InvalidOperationException(SR.Enumerator_NotStarted) when Current is accessed before the first MoveNext() call (_index == -1). WPF generated enumerators only allow Current reads while positioned on a valid element.
Solutions
- Call MoveNext() before reading Current
- Use foreach, which guarantees MoveNext precedes Current access
- Guard with a bool flag tracking whether MoveNext has succeeded
Example fix
// before var e = collection.GetEnumerator(); Console.WriteLine(e.Current); // throws // after var e = collection.GetEnumerator(); if (e.MoveNext()) Console.WriteLine(e.Current);
Defensive patterns
Strategy: type-guard
Validate before calling
bool canRead = enumeratorStarted; // true only after a MoveNext() returned true
Type guard
bool TryReadCurrent(System.Collections.IEnumerator e, out object? cur) { cur = null; if (e.MoveNext()) { cur = e.Current; return true; } return false; } Try / catch
try { var cur = e.Current; }
catch (InvalidOperationException) { /* MoveNext not called yet; call MoveNext first */ } Prevention
- Always call MoveNext() before reading Current
- Use foreach to avoid manual ordering mistakes
- Track enumerator state with a bool when hand-rolling loops
When it happens
Trigger: Reading e.Current immediately after GetEnumerator() without calling MoveNext(); reading Current in a while loop body before the first MoveNext returns true.
Common situations: Hand-written enumerator loops that inspect Current before advancing; refactorings that moved a Current read outside the loop condition.
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_ReachedEnd
- SR.Enumerator_ReachedEnd
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- Microsoft.Windows.Controls.SR.Ribbon_ContextualTabHeadersSou…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3d47fb28119f2178.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs:868
/// <summary>
/// Current element
///
/// The behavior of IEnumerable<T>.Current is undefined
/// before the first MoveNext and after we have walked
/// off the end of the list. However, the IEnumerable.Current
/// contract requires that we throw exceptions
/// </summary>
public Point3D Current
{
get
{
if (_index > -1)
{
return _current;
}
else if (_index == -1)
{
throw new InvalidOperationException(SR.Enumerator_NotStarted);
}
else
{
Debug.Assert(_index == -2, "expected -2, got " + _index + "\n");
throw new InvalidOperationException(SR.Enumerator_ReachedEnd);
}
}
}
#endregion
#region Data
private Point3D _current;
private Point3DCollection _list;
private uint _version;
private int _index;
#endregion
}View on GitHub (pinned to 81131a70a4)