dotnet/wpf · error · InvalidOperationException
SR.Enumerator_NotStarted
Error message
SR.Enumerator_NotStarted
What it means
Model3DCollection's enumerator Current property throws InvalidOperationException(SR.Enumerator_NotStarted) when accessed before the first MoveNext call (_index == -1). There is no valid 'current' element before iteration begins; accessing it early is a usage bug, not a data problem. (After the end, a different message, Enumerator_ReachedEnd, is thrown.)
Solutions
- Always call MoveNext and check it returned true before reading Current.
- Restructure to a foreach loop, which enforces correct Current access ordering.
- If you need the first element without an enumerator, use collection[0] (after checking Count).
Example fix
// before
var e = collection.GetEnumerator();
var first = e.Current; // InvalidOperationException: not started
// after
var e = collection.GetEnumerator();
if (e.MoveNext()) { var first = e.Current; } Defensive patterns
Strategy: validation
Validate before calling
if (!e.MoveNext()) return; // no elements; only then read e.Current
Type guard
bool HasCurrent(IEnumerator e) { try { return e.MoveNext(); } catch { return false; } } Try / catch
try { var cur = e.Current; } catch (InvalidOperationException ex) when (ex.Message.Contains("NotStarted")) { /* MoveNext was not called yet */ } Prevention
- Always call MoveNext before reading Current
- Prefer foreach over manual enumerator use
- Read the first element via collection[0] with a Count check when no iteration is needed
When it happens
Trigger: Reading enumerator.Current (or hitting it via foreach codegen misuse / manual enumerator loops) before calling MoveNext at least once; calling Current again after Reset without advancing.
Common situations: Hand-written enumerator loops with Current accessed outside the MoveNext loop condition; helper functions taking IEnumerator and peeking Current up front; after Reset() the state returns to -1 so an immediate Current read throws again.
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_CollectionChanged
- SR.Enumerator_CollectionChanged
- Cannot pass multidimensional array to the CopyTo method on…
- DoubleKeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8087086d2388d580.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Model3DCollection.cs:882
/// <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 Model3D 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 Model3D _current;
private Model3DCollection _list;
private uint _version;
private int _index;
#endregion
}View on GitHub (pinned to 81131a70a4)