Skip to content

Fix KeyboardToolTipStateMachine KeyNotFoundException when focus changes during tooltip popup event - #14731

Merged
LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14729_KeyNotFoundException
Jul 15, 2026
Merged

LeafShi1 merged 2 commits into
dotnet:mainfrom
LeafShi1:Fix_14729_KeyNotFoundException

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #14729

Root Cause

Calling Focus() in ToolTip.Popup event causes re-entrant focus change that creates invalid state-event combinations, triggering KeyNotFoundException. Timer callbacks on unhooked tools cause ArgumentNullException.

Proposed changes

  • Replace throw new KeyNotFoundException() with FullFsmReset()
  • Add null check in Transit() method before accessing weak reference table

Customer Impact

  • Applications no longer crash during focus re-entrance in Popup events

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

Switching focus to the second text box using the Tab key triggers an /ArgumentNullException pop-up.

in .NET framework 4.8.1:

Image

in .net10 application:

image

After

App continues running

AfterChanges.mp4

Test methodology

  • Manually

Test environment(s)

  • .net 11.0.0-preview.7.26355.102
Microsoft Reviewers: Open in CodeFlow

@LeafShi1
LeafShi1 requested a review from Copilot July 14, 2026 06:22
@LeafShi1
LeafShi1 marked this pull request as ready for review July 14, 2026 06:22
@LeafShi1
LeafShi1 requested a review from a team as a code owner July 14, 2026 06:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes crashes in WinForms keyboard ToolTip handling when focus changes re-entrantly during ToolTip.Popup, by making the KeyboardToolTipStateMachine more resilient to unexpected transitions and late timer callbacks.

Changes:

  • Replace the “unknown transition” fallback from throwing KeyNotFoundException to performing a full FSM reset.
  • Add a guard in Transit() to handle a null source (e.g., from late timer callbacks) and reset safely.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LeafShi1

Copy link
Copy Markdown
Member Author

As a workaround, changing the synchronous _first.Focus() call inside the Popup to an asynchronous one:
BeginInvoke(() => _first.Focus())

@LeafShi1
LeafShi1 marked this pull request as draft July 14, 2026 09:32
@dotnet-policy-service dotnet-policy-service Bot added the draft draft PR label Jul 14, 2026
@KlausLoeffelmann
KlausLoeffelmann marked this pull request as ready for review July 14, 2026 19:35

@KlausLoeffelmann KlausLoeffelmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's take it.

@dotnet-policy-service dotnet-policy-service Bot removed the draft draft PR label Jul 14, 2026
@LeafShi1
LeafShi1 merged commit af397d2 into dotnet:main Jul 15, 2026
8 checks passed
@LeafShi1 LeafShi1 added the releasenotes-candidate This issue is a candidate to be mentioned in the release notes, if the respective PR fixed it. label Jul 15, 2026
@LeafShi1 LeafShi1 added this to the 11.0-preview7 milestone Jul 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

releasenotes-candidate This issue is a candidate to be mentioned in the release notes, if the respective PR fixed it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyboardToolTipStateMachine KeyNotFoundException thrown

3 participants