dotnet/wpf · error · InvalidOperationException
SR.Enumerator_NotStarted
Error message
SR.Enumerator_NotStarted
What it means
PathFigureCollection.Enumerator.Current throws InvalidOperationException with SR.Enumerator_NotStarted when Current is read before the first call to MoveNext(). The enumerator uses _index == -1 to mean 'not started' and refuses to return a Current value in that state.
Solutions
- Call MoveNext() at least once before reading Current.
- Use a foreach loop instead of manual enumerator handling so the protocol is enforced.
- Reset the enumerator (or get a new one) if it was consumed and you need to iterate again.
Example fix
// before
var e = figures.GetEnumerator();
var first = e.Current;
// after
var e = figures.GetEnumerator();
if (e.MoveNext())
{
var first = e.Current;
} Defensive patterns
Strategy: type-guard
Validate before calling
var e = figures.GetEnumerator(); if (!e.MoveNext()) return; // empty collection ProcessCurrent(e.Current);
Type guard
bool TryGetFirst(PathFigureCollection c, out PathFigure first)
{
var e = c.GetEnumerator();
if (e.MoveNext()) { first = e.Current; return true; }
first = null; return false;
} Try / catch
try
{
var value = enumerator.Current;
}
catch (InvalidOperationException)
{
// enumerator not started; call MoveNext() first
} Prevention
- Prefer foreach over manual enumerator protocols.
- Always pair the first Current read with a successful MoveNext().
When it happens
Trigger: Accessing the Current property of a PathFigureCollection enumerator immediately after GetEnumerator() without calling MoveNext() first.
Common situations: Hand-written enumerator loops that forget the initial MoveNext; code that stores an enumerator and reads Current speculatively; misused LINQ replacements or manual foreach expansions.
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
- InvalidOperationException
- SR.Enumerator_CollectionChanged
- SR.Enumerator_NotStarted
- SR.Enumerator_NotStarted
- SR.Enumerator_NotStarted
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/766fd36c8288ddc1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollection.cs:939
/// <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 PathFigure 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 PathFigure _current;
private PathFigureCollection _list;
private uint _version;
private int _index;
#endregion
}View on GitHub (pinned to 81131a70a4)