MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · InvalidOperationException
No loaded DialogHost have an {nameof(Identifier)} property m
Error message
No loaded DialogHost have an {nameof(Identifier)} property matching {nameof(dialogIdentifier)} ('{dialogIdentifier}') argument. What it means
After confirming at least one `DialogHost` is loaded, `GetInstance` filters by matching `Equals(dialogIdentifier, instance.Identifier)`. If none match it throws `InvalidOperationException` reporting that no loaded host has an `Identifier` matching the supplied `dialogIdentifier`. Note a null identifier matches hosts whose `Identifier` is also null.
Source
Thrown at src/MaterialDesignThemes.Wpf/DialogHost.cs:251
}
else
{
// 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;
View on GitHub (pinned to 98edec3a0b)
Solutions
- Use the exact same `Identifier` value in XAML and in `Show`/`Close` calls (define it once as a const/shared key).
- If you set no identifier in XAML, call Show/Close with `null`.
- Ensure the identifier type's `Equals`/`GetHashCode` behave as you expect (strings, enums, records are fine; custom objects may not).
- Double-check spelling/casing of string identifiers.
Example fix
<!-- before -->
<materialDesign:DialogHost Identifier="root" />
await DialogHost.Show(vm, "RootDialog"); // mismatch -> throws
<!-- after (single source of truth) -->
<materialDesign:DialogHost Identifier="{x:Static local:DialogIds.Root}" />
await DialogHost.Show(vm, DialogIds.Root); Defensive patterns
Strategy: validation
Validate before calling
object id = DialogIds.Root; // shared with XAML Identifier await DialogHost.Show(content, id);
Type guard
static bool IdentifierIsMounted(object id)
=> DialogHost.GetDialogSession(id) is not null || DialogHost.IsDialogOpen(id) || /* loaded */ true; Try / catch
try { await DialogHost.Show(content, id); }
catch (InvalidOperationException ex) when (ex.Message.Contains("matching"))
{ /* identifier typo: log expected id */ } Prevention
- Define the identifier once and reference it from both XAML and code.
- Use null consistently if no identifier is configured.
- Ensure identifier types have correct Equals/GetHashCode semantics.
When it happens
Trigger: Calling Show/Close with an identifier that does not equal any loaded host's `Identifier` (typo, different casing won't matter since it's `Equals`, but wrong value will), or with a non-null identifier when hosts are configured with null identifiers.
Common situations: Identifier mismatch between XAML (`Identifier="root"`) and code (`Show(content, "RootDialog")`); renaming the identifier in one place only; using an enum/object identifier that doesn't `Equals` the configured one; passing an identifier when the host has none.
Related errors
- Multiple viable DialogHosts. Specify a unique Identifier on
- 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/faf492b0fae3cf68.
Report an issue: GitHub.