{"record":{"id":"82cf40cbb84e3cdc","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"dialoghost-is-not-open","errorCode":null,"errorMessage":"DialogHost is not open.","messagePattern":"DialogHost is not open\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/DialogHost.cs","lineNumber":198,"sourceCode":"    /// </summary>\n    /// <param name=\"dialogIdentifier\"> of the instance where the dialog should be closed. Typically this will match an identifier set in XAML. </param>\n    public static void Close(object? dialogIdentifier)\n        => Close(dialogIdentifier, null);\n\n    /// <summary>\n    ///  Close a modal dialog.\n    /// </summary>\n    /// <param name=\"dialogIdentifier\"> of the instance where the dialog should be closed. Typically this will match an identifier set in XAML. </param>\n    /// <param name=\"parameter\"> Value returned by DialogHost.ShowDialog(...) or passed to close handler if one is provided.</param>\n    public static void Close(object? dialogIdentifier, object? parameter)\n    {\n        DialogHost dialogHost = GetInstance(dialogIdentifier);\n        if (dialogHost.CurrentSession is { } currentSession)\n        {\n            currentSession.Close(parameter);\n            return;\n        }\n        throw new InvalidOperationException(\"DialogHost is not open.\");\n    }\n\n    /// <summary>\n    /// Retrieve the current dialog session for a DialogHost\n    /// </summary>\n    /// <param name=\"dialogIdentifier\">The identifier to use to retrieve the DialogHost</param>\n    /// <returns>The DialogSession if one is in process, or null</returns>\n    public static DialogSession? GetDialogSession(object? dialogIdentifier)\n    {\n        DialogHost dialogHost = GetInstance(dialogIdentifier);\n        return dialogHost.CurrentSession;\n    }\n\n    /// <summary>\n    /// dialog instance exists\n    /// </summary>\n    /// <param name=\"dialogIdentifier\">of the instance where the dialog should be closed. Typically this will match an identifier set in XAML.</param>\n    /// <returns></returns>","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/DialogHost.cs#L180-L216","documentation":"`DialogHost.Close(object? dialogIdentifier, object? parameter)` looks up the host instance and, if it has no active `CurrentSession`, throws `InvalidOperationException(\"DialogHost is not open.\")`. It means you tried to close a dialog that was never opened (or was already closed) under that identifier.","triggerScenarios":"Calling `DialogHost.Close(identifier)` when no dialog is currently shown for that identifier; double-closing; closing after the dialog already ended; closing before `Show` was called.","commonSituations":"Race between a close command and the dialog not yet opened; close handlers firing twice; closing on a different identifier than the one used to show; closing after the user already dismissed the dialog.","solutions":["Check `DialogHost.IsDialogOpen(identifier)` (or `GetDialogSession`) before calling `Close`.","Guard against double-close by disabling the close command after first invocation.","Ensure the same `dialogIdentifier` is used for `Show` and `Close`.","Catch `InvalidOperationException` around programmatic close if the dialog may already be gone."],"exampleFix":"// before\nDialogHost.Close(\"RootDialog\"); // throws if nothing is open\n\n// after\nif (DialogHost.IsDialogOpen(\"RootDialog\"))\n    DialogHost.Close(\"RootDialog\");","handlingStrategy":"validation","validationCode":"if (DialogHost.IsDialogOpen(DialogIds.Root))\n    DialogHost.Close(DialogIds.Root);","typeGuard":"static bool CanClose(object identifier) => DialogHost.IsDialogOpen(identifier);","tryCatchPattern":"try { DialogHost.Close(DialogIds.Root); }\ncatch (InvalidOperationException) { /* already closed: ignore */ }","preventionTips":["Check IsDialogOpen before Close.","Use the same identifier for Show and Close.","Disable close commands after first use to avoid double-close."],"tags":["wpf","dialog","lifecycle","state-error","material-design"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}