dotnet/wpf · error · InvalidOperationException
SR.Enumerator_NotStarted
Error message
SR.Enumerator_NotStarted
What it means
BitmapMetadataEnumerator's Current property (IEnumerable MoveNext/Current pattern) throws InvalidOperationException with SR.Enumerator_NotStarted when Current is accessed before MoveNext has ever been called. WPF metadata enumerators follow the standard .NET enumerator contract: there is no valid current element until iteration begins.
Solutions
- Call MoveNext() at least once and only read Current when it returns true.
- Replace manual enumerator code with a foreach loop, which handles MoveNext ordering automatically.
- Check enumerator state before accessing Current if you store the enumerator across calls.
Example fix
// before
var e = metadata.GetEnumerator();
Console.WriteLine(e.Current); // throws
// after
var e = metadata.GetEnumerator();
while (e.MoveNext())
Console.WriteLine(e.Current); Defensive patterns
Strategy: validation
Validate before calling
if (enumerator is null) throw new ArgumentNullException(nameof(enumerator)); // track state before reading Current bool started = false;
Type guard
bool CanReadCurrent(IEnumerator e, bool lastMoveNextTrue) => lastMoveNextTrue;
Try / catch
try { var cur = e.Current; } catch (InvalidOperationException) { /* not started; call MoveNext first */ } Prevention
- Always pair Current with a preceding successful MoveNext()
- Prefer foreach over manual enumerators
- Never cache and read Current across MoveNext boundaries
When it happens
Trigger: Reading the Current property of a BitmapMetadata enumerator (e.g. foreach-variable misuse or manual enumerator use) immediately after calling GetEnumerator() without a prior MoveNext() returning true.
Common situations: Hand-written loops over BitmapMetadata query strings using IEnumerator<string> where the developer forgets the initial MoveNext(); porting COM/IWICMetadataQueryReader code that assumes a 'first element' is already current.
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/750c323b36c8677a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadataEnumerator.cs:126
#endregion // Methods
#endregion // IEnumerator interface
#region Properties
/// <summary>
/// The current timeline referenced by this enumerator.
/// </summary>
public String Current
{
get
{
if (_current == null)
{
if (!_fStarted)
{
throw new InvalidOperationException(SR.Enumerator_NotStarted);
}
else
{
throw new InvalidOperationException(SR.Enumerator_ReachedEnd);
}
}
return _current;
}
}
/// <summary>
///
/// </summary>
void IDisposable.Dispose()
{
// Do nothing - Required by the IEnumerable contract.
}View on GitHub (pinned to 81131a70a4)