{"record":{"id":"2fa137437ee7f376","repo":"tui-cs/Terminal.Gui","slug":"popovers-must-be-registered-before-being-shown","errorCode":null,"errorMessage":"Popovers must be registered before being shown.","messagePattern":"Popovers must be registered before being shown\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/App/ApplicationPopover.cs","lineNumber":184,"sourceCode":"    }\n\n    /// <summary>\n    ///     Shows <paramref name=\"popover\"/>. IPopoverView implementations should use OnVisibleChanaged/VisibleChanged to be\n    ///     notified when the user has done something to cause the popover to be hidden.\n    /// </summary>\n    /// <remarks>\n    ///     <para>\n    ///         This API calls <see cref=\"Register\"/>. To disable the popover from processing keyboard events,\n    ///         either call <see cref=\"DeRegister\"/> to\n    ///         remove the popover from the application or set <see cref=\"IPopoverView.Enabled\"/> to <see langword=\"false\"/>.\n    ///     </para>\n    /// </remarks>\n    /// <param name=\"popover\"></param>\n    public void Show (IPopoverView? popover)\n    {\n        if (!IsRegistered (popover))\n        {\n            throw new InvalidOperationException (@\"Popovers must be registered before being shown.\");\n        }\n\n        // Prevent re-show of a popover that was just dismissed by a mouse-press-outside event.\n        // The dismiss logic in ApplicationMouse.RaiseMouseEvent sets DismissedByMousePress before recursing,\n        // and the guard spans the entire press → release → click cycle. This prevents views beneath\n        // the popover from re-opening the same popover during the click that dismissed it.\n        if (popover is { } && App?.Mouse is ApplicationMouse { DismissedByMousePress: { } dismissed } && dismissed == popover)\n        {\n            return;\n        }\n\n        // If there's an existing popover, hide it.\n        if (_activePopover is { })\n        {\n            _activePopover.Visible = false;\n            _activePopover = null;\n        }\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/App/ApplicationPopover.cs#L166-L202","documentation":"Thrown by ApplicationPopover.Show when the passed IPopoverView is not in the registered popover set. Popovers must first be registered via Register (or Popovers.Register) so the application can track them for keyboard dispatch and lifecycle. Calling Show directly on an unregistered view bypasses that tracking, so the library refuses.","triggerScenarios":"Constructing a popover view and calling app.Popovers.Show(view) without a prior app.Popovers.Register(view) call; using a fresh popover instance each time instead of reusing the registered one.","commonSituations":"Ad-hoc context-menu or tooltip code that builds a new Popover each invocation; copy-pasting a snippet that omits the Register step; assuming Show auto-registers (it does not, despite the XML remark referencing Register).","solutions":["Register the popover once before showing: app.Popovers.Register(myPopover); then app.Popovers.Show(myPopover);.","Reuse the same registered popover instance across show/hide cycles rather than creating new ones.","If the popover may already be registered, guard with IsRegistered before calling Show."],"exampleFix":"// before\nvar menu = new PopoverMenu (...);\napp.Popovers.Show (menu); // throws — not registered\n\n// after\napp.Popovers.Register (menu);\napp.Popovers.Show (menu);","handlingStrategy":"validation","validationCode":"if (!app.Popovers.IsRegistered (popover))\n{\n    app.Popovers.Register (popover);\n}\napp.Popovers.Show (popover);","typeGuard":"static bool IsPopoverRegistered (ApplicationPopover p, IPopoverView v) => p.IsRegistered (v);","tryCatchPattern":null,"preventionTips":["Always Register a popover before Show.","Reuse the same registered instance across show/hide cycles.","Guard with IsRegistered if registration state is uncertain."],"tags":["popover","lifecycle","registration"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}