{"record":{"id":"0014f692a8532c70","repo":"dotnet/wpf","slug":"enumerator-for-core-properties-is-positioned-outside-bounds","errorCode":null,"errorMessage":"Enumerator for core properties is positioned outside bounds of collection.","messagePattern":"Enumerator for core properties is positioned outside bounds of collection\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/CorePropertiesFilter.cs","lineNumber":406,"sourceCode":"            get\n            {\n                ValidateCurrent();\n                return GetValue(CurrentGuid, CurrentPropId);\n            }\n        }\n\n        #endregion Internal properties\n\n        #region Private methods\n\n        /// <summary>\n        /// Check if the current entry in enumeration is valid.\n        /// </summary>\n        private void ValidateCurrent()\n        {\n            if (_currentIndex < 0 || _currentIndex >= _attributes.Length)\n            {\n                throw new InvalidOperationException(\n                    SR.CorePropertyEnumeratorPositionedOutOfBounds);\n            }\n        }\n\n        #endregion\n\n        #region Private properties\n\n        /// <summary>\n        /// Get value for the property corresponding to the\n        /// property set GUID and property ID.\n        /// </summary>\n        /// <param name=\"guid\">property set GUID</param>\n        /// <param name=\"propId\">property ID</param>\n        /// <returns>\n        /// property value which could be string or DateTime,\n        /// or null if it doesn't exist.\n        /// </returns>","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/CorePropertiesFilter.cs#L388-L424","documentation":"CorePropertiesFilter's internal enumerator walks the package's core property attributes. ValidateCurrent(), called by CurrentGuid, CurrentPropId, and CurrentValue, throws InvalidOperationException when the current index is negative or past the end of _attributes — i.e., the enumerator is not positioned on a valid entry.","triggerScenarios":"Accessing CurrentGuid/CurrentPropId/CurrentValue after enumeration completed (MoveNext returned false), before the first MoveNext, or after Reset without advancing.","commonSituations":"Iterating with a do/while that reads Current after the last MoveNext; calling Current* properties before starting enumeration; reusing a finished enumerator to read a 'last' item.","solutions":["Only access CurrentGuid/CurrentPropId/CurrentValue after a successful MoveNext() that returned true.","Check index bounds yourself before reading (track MoveNext result in a bool and gate access).","Catch InvalidOperationException and treat it as end-of-enumeration."],"exampleFix":"// before\nwhile (true) { Process(filter.CurrentValue); filter.MoveNext(); }\n// after\nwhile (filter.MoveNext()) { Process(filter.CurrentValue); }","handlingStrategy":"type-guard","validationCode":"bool positioned = movedNextSuccessfully; // result of last MoveNext() call","typeGuard":"static bool OnValidEntry(bool lastMoveNextResult) => lastMoveNextResult;","tryCatchPattern":"try { var v = filter.CurrentValue; } catch (InvalidOperationException) { /* enumeration not started or finished */ }","preventionTips":["Gate Current* access on the boolean result of MoveNext()","Never read Current before the first MoveNext or after the enumeration ends","Prefer foreach-style loops that cannot over-run"],"tags":["enumerator","index-out-of-range","wpf-packaging"],"backgroundTag":"index-out-of-bounds","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}