{"record":{"id":"441184166a41b28b","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"multiple-viable-dialoghosts-specify-a-unique-iden","errorCode":null,"errorMessage":"Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern.","messagePattern":"Multiple viable DialogHosts\\. Specify a unique Identifier on each DialogHost, especially where multiple Windows are a concern\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/DialogHost.cs","lineNumber":253,"sourceCode":"                {\n                    // Retrieve the identifier using the Dispatcher on the owning thread (effectively replaces the VerifyAccess() call previously used)\n                    identifier = dialogInstance.Dispatcher.Invoke(() => dialogInstance.Identifier);\n                }\n                if (Equals(dialogIdentifier, identifier))\n                {\n                    targets.Add(dialogInstance);\n                }\n            }\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;","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/DialogHost.cs#L235-L271","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before: two hosts, same identifier -->\n<materialDesign:DialogHost Identifier=\"RootDialog\" /> <!-- window A -->\n<materialDesign:DialogHost Identifier=\"RootDialog\" /> <!-- window B -->\nawait DialogHost.Show(vm, \"RootDialog\"); // throws: multiple viable\n\n<!-- after -->\n<materialDesign:DialogHost Identifier=\"MainDialog\" />  <!-- window A -->\n<materialDesign:DialogHost Identifier=\"ToolsDialog\" />  <!-- window B -->","handlingStrategy":"validation","validationCode":"// Give each concurrently loaded DialogHost a distinct Identifier.\n// Open with the specific identifier for the target window:\nawait DialogHost.Show(content, windowScopedId);","typeGuard":null,"tryCatchPattern":"try { await DialogHost.Show(content, id); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Multiple viable\"))\n{ /* disambiguate: close other hosts or use a unique id */ }","preventionTips":["Assign unique Identifiers to concurrently loaded DialogHosts.","Scope identifiers per window when multiple windows can be open.","Avoid leaving stray duplicate hosts mounted."],"tags":["wpf","dialog","identifier","configuration","material-design","multi-window"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}