peass-ng/PEASS-ng · error · InvalidOperationException

Dictionary was modified after this collection was created.

Error message

Dictionary was modified after this collection was created.

What it means

A fail-fast enumerator guard in RehashableDictionary's snapshot view: the view subscribes to the dictionary's Added/Removed events and sets Invalid on any change; CheckValid throws this InvalidOperationException when enumeration continues after the underlying dictionary was structurally modified — the same contract as .NET's Dictionary enumerator invalidation.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/RehashableDictionary.cs:417

            {
                Dictionary = dictionary;
                Dictionary.Added += DictionaryChanged;
                Dictionary.Removed += DictionaryChanged;
            }
            public void Dispose()
            {
                Dictionary.Added -= DictionaryChanged;
                Dictionary.Removed -= DictionaryChanged;
            }
            void DictionaryChanged(object sender, RehashableDictionary<K, V>.DictionaryEventArgs e)
            {
                Invalid = true;
            }

            protected void CheckValid()
            {
                if ( Invalid )
                    throw new InvalidOperationException(
                        "Dictionary was modified after this collection was created.");
            }

            static void ThrowReadOnlyError()
            {
                throw new InvalidOperationException("Collection is readonly.");
            }

            #region ICollection<K> メンバ

            public void Add(T item)
            { ThrowReadOnlyError(); }

            public void Clear()
            { ThrowReadOnlyError(); }

            public abstract bool Contains(T item);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Do not add/remove entries while enumerating; finish or break the enumeration first
  2. Copy entries to a list (ToList()) and iterate the copy when mutation is needed
  3. Re-fetch the enumerator after any modification
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/YamlSerializer/RehashableDictionary.cs:417 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/913ba9ba4eb92ced. Report an issue: GitHub.