MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · InvalidOperationException
DialogHost is already open.
Error message
DialogHost is already open.
What it means
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.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogHost.cs:261
}
else
{
LoadedInstances.Remove(instance);
}
}
if (targets.Count == 0)
throw new InvalidOperationException($"No loaded DialogHost have an {nameof(Identifier)} property matching {nameof(dialogIdentifier)} ('{dialogIdentifier}') argument.");
if (targets.Count > 1)
throw new InvalidOperationException("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern.");
return targets[0];
}
internal async Task<object?> ShowInternal(object content, DialogOpenedEventHandler? openedEventHandler, DialogClosingEventHandler? closingEventHandler, DialogClosedEventHandler? closedEventHandler)
{
if (IsOpen)
throw new InvalidOperationException("DialogHost is already open.");
_dialogTaskCompletionSource = new TaskCompletionSource<object?>();
AssertTargetableContent();
if (content != null)
DialogContent = content;
_asyncShowOpenedEventHandler = openedEventHandler;
_asyncShowClosingEventHandler = closingEventHandler;
_asyncShowClosedEventHandler = closedEventHandler;
SetCurrentValue(IsOpenProperty, true);
object? result = await _dialogTaskCompletionSource.Task;
_asyncShowOpenedEventHandler = null;
_asyncShowClosingEventHandler = null;
_asyncShowClosedEventHandler = null;View on GitHub (pinned to 98edec3a0b)
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).
Example fix
// before
await dialogHost.Show(contentA);
await dialogHost.Show(contentB); // may throw if A still open
// after
if (!dialogHost.IsOpen)
await dialogHost.Show(contentA); Defensive patterns
Strategy: validation
Validate before calling
if (dialogHost.IsOpen)
throw new InvalidOperationException("DialogHost is already showing; cannot open a second dialog.");
await dialogHost.Show(content); Try / catch
try
{
await dialogHost.Show(content);
}
catch (InvalidOperationException ex) when (ex.Message == "DialogHost is already open.")
{
// queue or ignore the redundant open attempt
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {nameof(DialogHost)} does not have a current session
- Dialog session has ended.
- Cannot cancel dialog closing after {nameof(IsOpen)} property
- Content cannot be passed to a dialog via the OpenDialog if D
- session
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/95f2da69f2ea46b8.
Report an issue: GitHub.