{"record":{"id":"89129bc10c2cea81","repo":"tui-cs/Terminal.Gui","slug":"hotkey-must-not-be-null-use-key-empty-to-clear-th","errorCode":null,"errorMessage":"HotKey must not be null. Use Key.Empty to clear the HotKey.","messagePattern":"HotKey must not be null\\. Use Key\\.Empty to clear the HotKey\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/ViewBase/View.Keyboard.cs","lineNumber":90,"sourceCode":"    ///         <see cref=\"AddKeyBindingsForHotKey\"/>.\n    ///     </para>\n    ///     <para>\n    ///         By default, when the HotKey is set to <see cref=\"Key.A\"/> through <see cref=\"Key.Z\"/> key bindings will\n    ///         be added for both the un-shifted and shifted versions. This means if the HotKey is <see cref=\"Key.A\"/>, key\n    ///         bindings for <c>Key.A</c> and <c>Key.A.WithShift</c> will be added. This behavior can be overriden by\n    ///         overriding <see cref=\"AddKeyBindingsForHotKey\"/>.\n    ///     </para>\n    ///     <para>If the hot key is changed, the <see cref=\"HotKeyChanged\"/> event is fired.</para>\n    ///     <para>Set to <see cref=\"Key.Empty\"/> to disable the hot key.</para>\n    /// </remarks>\n    public Key HotKey\n    {\n        get => _hotKey;\n        set\n        {\n            if (value is null)\n            {\n                throw new ArgumentException (@\"HotKey must not be null. Use Key.Empty to clear the HotKey.\", nameof (value));\n            }\n\n            if (!AddKeyBindingsForHotKey (_hotKey, value))\n            {\n                return;\n            }\n\n            // This will cause TextFormatter_HotKeyChanged to be called, firing HotKeyChanged\n            // BUGBUG: _hotkey should be set BEFORE setting TextFormatter.HotKey\n            _hotKey = value;\n            TitleTextFormatter.HotKey = value;\n        }\n    }\n\n    /// <summary>\n    ///     Adds key bindings for the specified HotKey. Useful for views that contain multiple items that each have their\n    ///     own HotKey such as <see cref=\"OptionSelector\"/>.\n    /// </summary>","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/ViewBase/View.Keyboard.cs#L72-L108","documentation":"The HotKey property does not accept a null Key. The library distinguishes 'no hot key assigned' (Key.Empty) from 'unset reference' (null) to keep the property non-nullable. Passing null indicates a programming error rather than intent to clear.","triggerScenarios":"Assigning view.HotKey = null; or passing a Key variable that was never initialized (default null because Key is a reference type in v2).","commonSituations":"C# nullable context disabled or ignored; conditional hot-key assignment where the branch leaves Key as null; deserializing a HotKey from JSON that omits the field.","solutions":["Use Key.Empty to clear/disable the hot key.","Ensure the Key variable is always assigned a concrete Key (e.g. Key.A) before assignment.","Enable nullable reference type warnings to catch null Key at compile time."],"exampleFix":"// before\nview.HotKey = condition ? Key.Q : null;\n// after\nview.HotKey = condition ? Key.Q : Key.Empty;","handlingStrategy":"validation","validationCode":"view.HotKey = key ?? Key.Empty;","typeGuard":"static Key NonNullHotKey (Key? k) => k ?? Key.Empty;","tryCatchPattern":null,"preventionTips":["Always assign a concrete Key or Key.Empty.","Enable nullable reference warnings.","Never use null to mean 'no hot key' — use Key.Empty."],"tags":["hotkey","keyboard","validation"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}