{"record":{"id":"750c323b36c8677a","repo":"dotnet/wpf","slug":"sr-enumerator-notstarted-bitmapmetadataenumerator","errorCode":null,"errorMessage":"SR.Enumerator_NotStarted","messagePattern":"SR\\.Enumerator_NotStarted","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadataEnumerator.cs","lineNumber":126,"sourceCode":"\n        #endregion // Methods\n\n        #endregion // IEnumerator interface\n\n        #region Properties\n        \n        /// <summary>\n        /// The current timeline referenced by this enumerator.\n        /// </summary>\n        public String Current\n        {\n            get\n            {\n                if (_current == null)\n                {\n                    if (!_fStarted)\n                    {\n                        throw new InvalidOperationException(SR.Enumerator_NotStarted);\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Enumerator_ReachedEnd);\n                    }\n                }\n\n                return _current;\n            }\n        }\n\n        /// <summary>\n        ///\n        /// </summary>\n        void IDisposable.Dispose()\n        {\n            // Do nothing - Required by the IEnumerable contract.\n        }","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapMetadataEnumerator.cs#L108-L144","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar e = metadata.GetEnumerator();\nConsole.WriteLine(e.Current); // throws\n// after\nvar e = metadata.GetEnumerator();\nwhile (e.MoveNext())\n    Console.WriteLine(e.Current);","handlingStrategy":"validation","validationCode":"if (enumerator is null) throw new ArgumentNullException(nameof(enumerator));\n// track state before reading Current\nbool started = false;","typeGuard":"bool CanReadCurrent(IEnumerator e, bool lastMoveNextTrue) => lastMoveNextTrue;","tryCatchPattern":"try { var cur = e.Current; } catch (InvalidOperationException) { /* not started; call MoveNext first */ }","preventionTips":["Always pair Current with a preceding successful MoveNext()","Prefer foreach over manual enumerators","Never cache and read Current across MoveNext boundaries"],"tags":["wpf","enumerator","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}