Skip to content

Do not use visual children enumerator in TopLevelHost#21048

Merged
MrJul merged 2 commits into
AvaloniaUI:masterfrom
MrJul:fix/toplevelhost-visualchildren-enumeration
Mar 31, 2026
Merged

Do not use visual children enumerator in TopLevelHost#21048
MrJul merged 2 commits into
AvaloniaUI:masterfrom
MrJul:fix/toplevelhost-visualchildren-enumeration

Conversation

@MrJul

@MrJul MrJul commented Mar 31, 2026

Copy link
Copy Markdown
Member

What does the pull request do?

This PR fixes an issue where if children are added to TopLevelHost dynamically while a measure pass is in progress, an InvalidOperationException: Collection was modified; enumeration operation may not execute is thrown.

This happens, for example, by setting Window.ExtendClientAreaToDecorationsHint = true in OnAttachedToVisualTree.

This is a general problem with the visual and logical children collection, and a solution such as #20028 will be implemented in the future.

In the meantime, change TopLevelHost to iterate using a plain old for loop, matching what's done in MeasureOverride/ArrangeOverride for all other controls.

@MrJul MrJul added bug wont-backport customer-priority Issue reported by a customer with a support agreement. labels Mar 31, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0064333-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added this pull request to the merge queue Mar 31, 2026
Merged via the queue into AvaloniaUI:master with commit 0842236 Mar 31, 2026
12 checks passed
@MrJul MrJul deleted the fix/toplevelhost-visualchildren-enumeration branch March 31, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug customer-priority Issue reported by a customer with a support agreement. wont-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants