MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · InvalidOperationException
Multiple viable DialogHosts. Specify a unique Identifier on
Error message
Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern.
What it means
If more than one loaded `DialogHost` has an `Identifier` matching the supplied `dialogIdentifier`, `GetInstance` cannot pick one and throws `InvalidOperationException("Multiple viable DialogHosts. Specify a unique Identifier...")`. Identifiers must be unique among simultaneously loaded hosts.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogHost.cs:253
{
// Retrieve the identifier using the Dispatcher on the owning thread (effectively replaces the VerifyAccess() call previously used)
identifier = dialogInstance.Dispatcher.Invoke(() => dialogInstance.Identifier);
}
if (Equals(dialogIdentifier, identifier))
{
targets.Add(dialogInstance);
}
}
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;View on GitHub (pinned to 98edec3a0b)
Solutions
- Give each concurrently loaded `DialogHost` a unique `Identifier`.
- When opening dialogs from a specific window, scope the identifier to that window.
- Unregister/close other hosts with the same identifier, or pass a window-specific identifier.
- If only one host is ever needed, ensure stray duplicate hosts (e.g. in another open window) are closed.
Example fix
<!-- before: two hosts, same identifier --> <materialDesign:DialogHost Identifier="RootDialog" /> <!-- window A --> <materialDesign:DialogHost Identifier="RootDialog" /> <!-- window B --> await DialogHost.Show(vm, "RootDialog"); // throws: multiple viable <!-- after --> <materialDesign:DialogHost Identifier="MainDialog" /> <!-- window A --> <materialDesign:DialogHost Identifier="ToolsDialog" /> <!-- window B -->
Defensive patterns
Strategy: validation
Validate before calling
// Give each concurrently loaded DialogHost a distinct Identifier. // Open with the specific identifier for the target window: await DialogHost.Show(content, windowScopedId);
Try / catch
try { await DialogHost.Show(content, id); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Multiple viable"))
{ /* disambiguate: close other hosts or use a unique id */ } Prevention
- Assign unique Identifiers to concurrently loaded DialogHosts.
- Scope identifiers per window when multiple windows can be open.
- Avoid leaving stray duplicate hosts mounted.
When it happens
Trigger: Two or more `DialogHost` instances in the visual tree share the same `Identifier` (or both have null identifiers), and you call Show/Close with that identifier.
Common situations: Multiple windows each with a `DialogHost` using the same identifier; a DialogHost in a main window plus another in a user control with the same identifier; reusing a well-known identifier like "RootDialog" across views that are loaded at the same time; all hosts left with null identifiers while several are loaded.
Related errors
- No loaded DialogHost have an {nameof(Identifier)} property m
- content
- DialogHost is not open.
- No loaded DialogHost instances.
- Unable to find a DialogHost with identifier '{dialogIdentifi
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/441184166a41b28b.
Report an issue: GitHub.