Skip to content

KeyboardToolTipStateMachine KeyNotFoundException thrown #14729

Closed

Description

@campbell-powerbrick

.NET version

.NET 10.0.9

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Tested in .NET 5 and it also threw the same exception

Issue description

Since migrating a .NET Framework WinForms solution to .NET 10 I've been getting KeyNotFoundException's occurring/being thrown - seemingly by Framework code. I've added a minimal reproducible example

System.Collections.Generic.KeyNotFoundException
  Message=The given key was not present in the dictionary.
  StackTrace:
   at System.Windows.Forms.KeyboardToolTipStateMachine.Transition(IKeyboardToolTip tool, ToolTip tooltip, SmEvent event)
   at System.Windows.Forms.KeyboardToolTipStateMachine.Transit(SmEvent event, IKeyboardToolTip source)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, UInt32 msg, WPARAM wparam, LPARAM lparam)
   at Windows.Win32.PInvoke.DispatchMessage(MSG* lpMsg)
   at System.Windows.Forms.Application.LightThreadContext.FPushMessageLoop(msoloop uReason)
   at System.Windows.Forms.Application.LightThreadContext.RunMessageLoop(msoloop reason, Boolean fullModal)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Program.Main() in ...\Program.cs:line 12

Steps to reproduce

using System;
using System.Drawing;
using System.Windows.Forms;

internal static class Program
{
    [STAThread]
    private static void Main()
    {
        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
        Application.ThreadException += (_, e) => MessageBox.Show(e.Exception.ToString(), "Reproduced");
        Application.Run(new ReproForm());
    }
}

internal sealed class ReproForm : Form
{
    private readonly TextBox _first = new TextBox() { Text = "First", Left = 20, Top = 30, Width = 200, TabIndex = 0 };
    private readonly TextBox _second = new TextBox() { Text = "Second", Left = 250, Top = 30, Width = 200, TabIndex = 1 };
    private readonly ToolTip _toolTip = new ToolTip()
    {
        InitialDelay = 50,
        ReshowDelay = 25,
        AutoPopDelay = 100,
        ShowAlways = true
    };
    private bool _redirected;

    public ReproForm()
    {
        Text = "Hold Tab for one second";
        ClientSize = new Size(470, 90);
        Controls.AddRange(new[] { _first, _second });
        _toolTip.SetToolTip(_first, "First tooltip");
        _toolTip.SetToolTip(_second, "Second tooltip");
        _toolTip.Popup += (_, __) =>
        {
            if (_redirected || !_second.Focused)
                return;

            _redirected = true;
            _first.Focus();
        };

        Shown += (_, __) => _first.Focus();
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
            _toolTip.Dispose();

        base.Dispose(disposing);
    }
}

Activity

  1. added
    untriaged
    on Jul 13, 2026
  2. Olina-Zhang commented on Jul 13, 2026

    @Olina-Zhang
    Member

    Also reproduce this issue in .NET framework 4.8.1 app when enabling tooltip quirk in application's app.config file:

    <runtime>
    	<AppContextSwitchOverrides value="Switch.System.Windows.Forms.UseLegacyToolTipDisplay=false" />
    </runtime>
    
    Image
  3. self-assigned this
    on Jul 13, 2026
  4. removed
    untriaged
    on Jul 14, 2026
  5. KlausLoeffelmann commented on Jul 14, 2026

    @KlausLoeffelmann
    Member

    @LeafShi1, this is a migration blocker from earlier NetFx version, FWIW.
    I think this is more than Prio 2.

  6. added this to the 11.0-preview7 milestone on Jul 16, 2026
  7. Zheng-Li01 commented on Jul 16, 2026

    @Zheng-Li01
    Member

    Verified the issue with .NET 11.0.100-preview7.26365.114 build, the issue has been fixed that no exception pops as below screenshot.

    VerifyIssue.mp4
  8. Amy-Li03 commented on Aug 3, 2026

    @Amy-Li03
    Contributor

    Verified on .NET 11 Preview 7 test pass build: .NET 11.0.100-preview.7.26381.103, issue was fixed, test result is same as above.

  9. GrahamClarkeQld commented on Aug 31, 2026

    @GrahamClarkeQld

    I have upgraded .Net to 11.0.0-preview.7.26381.103 but I still get this error in a C# WinForms app that isn't actually using a ToolTip:
    System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at System.Windows.Forms.KeyboardToolTipStateMachine.Transition(IKeyboardToolTip tool, ToolTip tooltip, SmEvent event)
    at System.Windows.Forms.KeyboardToolTipStateMachine.Transit(SmEvent event, IKeyboardToolTip source)
    at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

    I would appreciate being pointed to a resource that will show me how to perform a dump when the exception occurs.

  10. Olina-Zhang commented on Aug 31, 2026

    @Olina-Zhang
    Member

    @GrahamClarkeQld Can you please provide your Winforms app with that same exception occurred? We can test and investigate further. Thanks.

  11. GrahamClarkeQld commented on Aug 31, 2026

    @GrahamClarkeQld

    Silly me. My release exe file is now in a new folder under ...\bin\Release\net11.0-windows10.0.26100
    Please ignore my post

  12. locked and limited conversation to collaborators on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions