Skip to content

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

Open
LeafShi1 wants to merge 1 commit into
dotnet:mainfrom
LeafShi1:Fix_14729_KeyNotFoundException
Open

Fix KeyboardToolTipStateMachine KeyNotFoundException when focus changes during tooltip popup event#14731
LeafShi1 wants to merge 1 commit 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.

bool fullFsmResetRequired = false;
try
{
if (source is null)
Comment on lines +76 to +78
// Reentrant focus changes can yield event/state combinations outside the normal transition table.
// Resetting avoids surfacing framework exceptions to application code.
(_, _) => FullFsmReset()
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.

KeyboardToolTipStateMachine KeyNotFoundException thrown

2 participants