{"record":{"id":"95f2da69f2ea46b8","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"dialoghost-is-already-open","errorCode":null,"errorMessage":"DialogHost is already open.","messagePattern":"DialogHost is already open\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/DialogHost.cs","lineNumber":261,"sourceCode":"            }\n            else\n            {\n                LoadedInstances.Remove(instance);\n            }\n        }\n\n        if (targets.Count == 0)\n            throw new InvalidOperationException($\"No loaded DialogHost have an {nameof(Identifier)} property matching {nameof(dialogIdentifier)} ('{dialogIdentifier}') argument.\");\n        if (targets.Count > 1)\n            throw new InvalidOperationException(\"Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern.\");\n\n        return targets[0];\n    }\n\n    internal async Task<object?> ShowInternal(object content, DialogOpenedEventHandler? openedEventHandler, DialogClosingEventHandler? closingEventHandler, DialogClosedEventHandler? closedEventHandler)\n    {\n        if (IsOpen)\n            throw new InvalidOperationException(\"DialogHost is already open.\");\n\n        _dialogTaskCompletionSource = new TaskCompletionSource<object?>();\n\n        AssertTargetableContent();\n\n        if (content != null)\n            DialogContent = content;\n\n        _asyncShowOpenedEventHandler = openedEventHandler;\n        _asyncShowClosingEventHandler = closingEventHandler;\n        _asyncShowClosedEventHandler = closedEventHandler;\n        SetCurrentValue(IsOpenProperty, true);\n\n        object? result = await _dialogTaskCompletionSource.Task;\n\n        _asyncShowOpenedEventHandler = null;\n        _asyncShowClosingEventHandler = null;\n        _asyncShowClosedEventHandler = null;","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/DialogHost.cs#L243-L279","documentation":"Thrown by DialogHost.ShowInternal when IsOpen is already true on the same DialogHost instance. The DialogHost only supports one open dialog at a time; the guard at DialogHost.cs:260 rejects a second Show/ShowInternal call before the prior dialog's closing sequence completes and IsOpen flips back to false.","triggerScenarios":"Calling DialogHost.Show(...) (or ShowInternal via DialogHostEx.ShowDialog) twice on the same DialogHost instance while the first dialog is still open, e.g. awaiting one Show then invoking another Show on the same host before the first returns, or triggering from two event handlers simultaneously.","commonSituations":"Two commands/view-models racing to show a dialog on a shared single DialogHost; awaiting Show but re-entering on a UI event before the awaitable resolves; closing handlers that re-open; multiple Windows sharing one host.","solutions":["Guard the call site with 'if (!dialogHost.IsOpen) await dialogHost.Show(content);' before invoking Show.","Use a distinct DialogHost instance (separate Identifier) for each concurrent dialog you genuinely need.","Ensure the previous dialog's Close/CloseDialogCommand has fully resolved before starting the next; chain awaits serially rather than firing concurrently.","If overlapping dialogs are intentional, switch to a multi-host layout and address each by unique Identifier via DialogHost.Show(content, identifier)."],"exampleFix":"// before\nawait dialogHost.Show(contentA);\nawait dialogHost.Show(contentB); // may throw if A still open\n\n// after\nif (!dialogHost.IsOpen)\n    await dialogHost.Show(contentA);","handlingStrategy":"validation","validationCode":"if (dialogHost.IsOpen)\n    throw new InvalidOperationException(\"DialogHost is already showing; cannot open a second dialog.\");\n\nawait dialogHost.Show(content);","typeGuard":null,"tryCatchPattern":"try\n{\n    await dialogHost.Show(content);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"DialogHost is already open.\")\n{\n    // queue or ignore the redundant open attempt\n}","preventionTips":["Always check 'dialogHost.IsOpen' before calling Show.","Serialize dialog opens via awaits; never fire two Show calls concurrently on one host.","Use unique Identifiers per concurrent dialog rather than reusing a single host."],"tags":["wpf","materialdesigninxaml","dialog","state","concurrency"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}