Skip to content

Collection was modified; enumeration operation may not execute when running in Mono #2748

Description

@dawidprosba

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I try to use AlphaTab in Unity3D var api = new AlphaTabApiBase<Settings>(facade, settings); api, I'm getting

Error: Collection was modified; enumeration operation may not execute.

This edge case appears when using Mono framework that Unity3D is using.

I created C# Project (Ported it from my Unity3D project and vibe coded it to simplify it) but my code is not really important as it's in code where AlphaTab is handling beaming.

The error was introduced in one of the early 1.8 versions, the 1.8.0-alpha.1640 was latest working.

I tracked the error to:

Confirmed the pattern with custom snippet, which basically modifies the dictionary while we are looping over it. (That's what mono doesn't like)

            var dict = new Dictionary<int, int> { {1,1}, {2,2}, {3,3} };
            foreach (var v in dict.Values)
            {
                dict[v + 10] = v; // modify during iteration
                Debug.Log(v);
            }

Expected Behavior

When using Mono framework (Basically in Unity3D) and calling api.Load(score); I expect it to not throw error and in debugger print

Render complete
[DBG] Rendering: Rendering finished

Confirming it didnt fail

Steps To Reproduce

Reproducing from scratch:

  1. Use any version after 1.8.0-alpha.1640 (Error introduced between 1.7 -> 1.8)
  2. Use Mono Framework .csproj (<TargetFramework>net481</TargetFramework>)
  3. Install any version of AlphaTab after 1.8.0-alpha.1640 (The 1.8.0-alpha.1640 is the latest working with mono)
  4. Load Score from file and then load it using api api.Load(score);
  5. Error: Collection was modified; enumeration operation may not execute. will appear.

Reproducing in my example project:

  1. Clone my project https://github.com/dawidprosba/issue-alpha-tab-error/ and initialize it.
  2. You need to have mono installed I'm on mac so I ran brew install mono (https://formulae.brew.sh/formula/mono)
  3. Run mono-with-error-latest-version (Error path)
  4. You should see Error: Collection was modified; enumeration operation may not execute. among other logs. (Error will be at the bottom`
  5. Run mono-without-error-version-when-it-was-working (Happy path)
  6. You should see Render Complete and [DBG] Rendering: Rendering Finished
  7. Run net90-no-error (Happy path)
  8. You should see Render Complete and [DBG] Rendering: Rendering Finished

Link to jsFiddle, CodePen, Project

https://github.com/dawidprosba/issue-alpha-tab-error

Version and Environment

[DBG] VersionInfo: alphaTab 1.9.0-alpha.1813
[DBG] VersionInfo: commit: b6031affe32bc709f352b9f7ee70e51b983a4b4c
[DBG] VersionInfo: build date: 2026-05-25T04:46:13.698Z
[DBG] VersionInfo: High DPI: 1
[DBG] VersionInfo: .net Runtime: Mono 6.14.1 (tarball Tue Apr 29 17:43:02 UTC 2025)
[DBG] VersionInfo: Process: Arm64
[DBG] VersionInfo: OS Description: Unix 25.5.0.0
[DBG] VersionInfo: OS Arch: Arm64
[DBG] VersionInfo: alphaTab 1.9.0-alpha.1813
[DBG] VersionInfo: commit: b6031affe32bc709f352b9f7ee70e51b983a4b4c
[DBG] VersionInfo: build date: 2026-05-25T04:46:13.698Z
[DBG] VersionInfo: High DPI: 1
[DBG] VersionInfo: .net Runtime: Mono 6.14.1 (tarball Tue Apr 29 17:43:02 UTC 2025)
[DBG] VersionInfo: Process: Arm64
[DBG] VersionInfo: OS Description: Unix 25.5.0.0
[DBG] VersionInfo: OS Arch: Arm64
[DBG] ScoreLoader: Loading score from 1282 bytes using 6 importers
[DBG] ScoreLoader: Importing using importer Guitar Pro 3-5
[DBG] ScoreLoader: Guitar Pro 3-5 does not support the file
[DBG] ScoreLoader: Importing using importer Guitar Pro 6
[DBG] Guitar Pro 6: Loading GPX filesystem
[DBG] ScoreLoader: Guitar Pro 6 does not support the file
[DBG] ScoreLoader: Importing using importer Guitar Pro 7-8
[DBG] Guitar Pro 7-8: Loading ZIP entries
[DBG] Guitar Pro 7-8: Zip entries loaded
[DBG] ScoreLoader: Guitar Pro 7-8 does not support the file
[DBG] ScoreLoader: Importing using importer MusicXML
[DBG] ScoreLoader: Score imported using MusicXML
[DBG] AlphaTab: Generating Midi
[DBG] Midi: Begin midi generation
[DBG] Midi: Midi generation done
[DBG] AlphaTab: Generating Midi
[DBG] Midi: Begin midi generation
[DBG] Midi: Midi generation done
[DBG] Rendering: Rendering 1 tracks
[DBG] Rendering: Track 0: Piano
[DBG] Rendering: Rendering at scale 1 with layout PageView
[DBG] ScoreLayout: Creating score info glyphs
[DBG] PageView: Layouting score info
[ERR] API: An unexpected error occurred
Error: Collection was modified; enumeration operation may not execute.

Platform

.net (Other)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions