dotnet/wpf · error · InvalidOperationException

Enumerator for core properties is positioned outside bounds…

Error message

Enumerator for core properties is positioned outside bounds of collection.

What it means

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.

Solutions

  1. Only access CurrentGuid/CurrentPropId/CurrentValue after a successful MoveNext() that returned true.
  2. Check index bounds yourself before reading (track MoveNext result in a bool and gate access).
  3. Catch InvalidOperationException and treat it as end-of-enumeration.

Example fix

// before
while (true) { Process(filter.CurrentValue); filter.MoveNext(); }
// after
while (filter.MoveNext()) { Process(filter.CurrentValue); }
Defensive patterns

Strategy: type-guard

Validate before calling

bool positioned = movedNextSuccessfully; // result of last MoveNext() call

Type guard

static bool OnValidEntry(bool lastMoveNextResult) => lastMoveNextResult;

Try / catch

try { var v = filter.CurrentValue; } catch (InvalidOperationException) { /* enumeration not started or finished */ }

Prevention

When it happens

Trigger: Accessing CurrentGuid/CurrentPropId/CurrentValue after enumeration completed (MoveNext returned false), before the first MoveNext, or after Reset without advancing.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/0014f692a8532c70. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/CorePropertiesFilter.cs:406

            get
            {
                ValidateCurrent();
                return GetValue(CurrentGuid, CurrentPropId);
            }
        }

        #endregion Internal properties

        #region Private methods

        /// <summary>
        /// Check if the current entry in enumeration is valid.
        /// </summary>
        private void ValidateCurrent()
        {
            if (_currentIndex < 0 || _currentIndex >= _attributes.Length)
            {
                throw new InvalidOperationException(
                    SR.CorePropertyEnumeratorPositionedOutOfBounds);
            }
        }

        #endregion

        #region Private properties

        /// <summary>
        /// Get value for the property corresponding to the
        /// property set GUID and property ID.
        /// </summary>
        /// <param name="guid">property set GUID</param>
        /// <param name="propId">property ID</param>
        /// <returns>
        /// property value which could be string or DateTime,
        /// or null if it doesn't exist.
        /// </returns>

View on GitHub (pinned to 81131a70a4)