{"record":{"id":"6a097fa36103f800","repo":"MahApps/MahApps.Metro","slug":"active-dialog-container-could-not-be-found","errorCode":null,"errorMessage":"Active dialog container could not be found.","messagePattern":"Active dialog container could not be found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Dialogs/DialogManager.cs","lineNumber":220,"sourceCode":"\n                DialogClosed?.Invoke(window, new DialogStateChangedEventArgs(dialog));\n\n                await dialog.WaitForCloseAsync();\n\n                window.SizeChanged -= dialog.SizeChangedHandler;\n                window.RemoveDialog(dialog);\n\n                await HandleOverlayOnHideAsync(settings, window);\n            }\n\n            return new ProgressDialogController(dialog, CloseCallBack);\n        }\n\n        private static async Task HandleOverlayOnHideAsync(MetroDialogSettings? settings, MetroWindow window)\n        {\n            if (window.metroActiveDialogContainer is null)\n            {\n                throw new InvalidOperationException(\"Active dialog container could not be found.\");\n            }\n\n            var isAnyDialogOpen = window.metroActiveDialogContainer.Children.OfType<BaseMetroDialog>().Any();\n            if (!isAnyDialogOpen)\n            {\n                if (settings is null || settings.AnimateHide)\n                {\n                    await window.HideOverlayAsync();\n                }\n                else\n                {\n                    // ReSharper disable once MethodHasAsyncOverload\n                    window.HideOverlay();\n                }\n            }\n\n            if (window.metroActiveDialogContainer.Children.Count == 0)\n            {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Dialogs/DialogManager.cs#L202-L238","documentation":"DialogManager.HandleOverlayOnHideAsync runs after a dialog closes to manage the overlay and close button state. It requires window.metroActiveDialogContainer (a Grid resolved from the MetroWindow control template part PART_MetroActiveDialogContainer). If that field is null the method throws InvalidOperationException because there is no container to inspect/clear. The same message is reused at multiple call sites.","triggerScenarios":"A dialog is being hidden/removed from a MetroWindow whose template never supplied the PART_MetroActiveDialogContainer part — i.e. a heavily customized MetroWindow ControlTemplate that omitted the required template part — so the field resolved in OnApplyTemplate/MetroWindow.cs:1426 stayed null.","commonSituations":"A custom MetroWindow ControlTemplate was authored without the 'PART_MetroActiveDialogContainer' Grid (and the inactive container). Someone replaced the default MetroWindow template for styling and dropped the required parts. Wrong/older template resource merged that predates the dialog feature.","solutions":["Restore the PART_MetroActiveDialogContainer (and PART_MetroInactiveDialogsContainer) Grid(s) in your custom MetroWindow ControlTemplate so GetTemplateChild resolves them."],"exampleFix":"<!-- before: custom MetroWindow template missing the dialog part -->\n<ControlTemplate TargetType=\"{x:Type controls:MetroWindow}\">\n  <Grid> ... <!-- no active dialog container --> </Grid>\n</ControlTemplate>\n<!-- after: include the required named part -->\n<ControlTemplate TargetType=\"{x:Type controls:MetroWindow}\">\n  <Grid>\n    ...\n    <Grid x:Name=\"PART_MetroActiveDialogContainer\"/>\n    <Grid x:Name=\"PART_MetroInactiveDialogsContainer\"/>\n  </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Before showing/hiding dialogs, assert the template part resolved\nif (window.metroActiveDialogContainer is null) {\n    throw new InvalidOperationException(\n        \"MetroWindow template is missing PART_MetroActiveDialogContainer; cannot manage dialogs.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await dialogCoordinator.HideMetroDialogAsync(context, dialog);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"Active dialog container could not be found\")) {\n    // alert that the MetroWindow template is missing the required part; do not retry\n}","preventionTips":["Keep the default MetroWindow ControlTemplate, or carefully include both PART_MetroActiveDialogContainer and PART_MetroInactiveDialogsContainer in custom templates.","Add a design-time/template check that GetTemplateChild returns non-null for required parts.","Document required template parts in your custom MetroWindow style.","Avoid removing or renaming PART_ elements when restyling."],"tags":["wpf","dialog","metro-window","control-template","template-part","runtime"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}