Skip to content

ScrollViewerAssist: Avoid TargetInvocationException on WinForms application shutdown#4015

Merged
Keboo merged 1 commit intomasterfrom
fixIssue3439
Mar 6, 2026
Merged

ScrollViewerAssist: Avoid TargetInvocationException on WinForms application shutdown#4015
Keboo merged 1 commit intomasterfrom
fixIssue3439

Conversation

@nicolaihenriksen
Copy link
Contributor

@nicolaihenriksen nicolaihenriksen commented Mar 5, 2026

Fixes #3439

I have pushed a branch called reproduceIssue3439 which has a WinForms demo application showcasing the issue and the fix. The last commit on the branch, is the same commit (content) as the fix in this PR. Simply revert that if you want to see the error occurring on application shutdown.

In a use case where a TabControl is hosted in an ElementHost inside of a WinForms application, the handlers were not removed, and thus an exception was thrown during application shutdown.

This PR registers a HwndSourceHook which acts on the WM_DESTROY and WM_NCDESTROY messages in order to clean up the handlers (and unregister the hook to avoid memory leaks)

In a use case where a TabControl is hosted in an ElementHost inside of a WinForms application, the handlers were not removed, and thus an exception was thrown during application shutdown.
@nicolaihenriksen nicolaihenriksen changed the title Remove ScrollViewerAssist weak event handlers on WM_DESTROY ScrollViewerAssist: Avoid TargetInvocationException on WinForms application shutdown Mar 5, 2026
@nicolaihenriksen nicolaihenriksen added this to the 5.3.1 milestone Mar 5, 2026
Copy link
Member

@Keboo Keboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on stream if you are interested. Lgtm.

@Keboo Keboo merged commit 177d663 into master Mar 6, 2026
2 checks passed
@Keboo Keboo deleted the fixIssue3439 branch March 6, 2026 05:44
nicolaihenriksen added a commit that referenced this pull request Mar 9, 2026
* Revert "Remove ScrollViewerAssist weak event handlers on WM_DESTROY (#4015)"

This reverts commit 177d663.

* Fix issue by for BubbleVerticalScroll

* Fix issue by for HorizontalScroll

* Cleanup: revert not needed signature change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a TabControl triggers a TargetInvocationException at App shutdown, when the WPF Control is hosted in a Winform Elementhost

2 participants