{"record":{"id":"af3770d06295a3a7","repo":"PrismLibrary/Prism","slug":"error-creating-dialog-name","errorCode":null,"errorMessage":"Error creating dialog '{name}'","messagePattern":"Error creating dialog '(.+?)'","errorType":"exception","errorClass":"ViewCreationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs","lineNumber":31,"sourceCode":"/// </summary>\npublic abstract class DialogServiceBase : IDialogService\n{\n    /// <inheritdoc/>\n    public void ShowDialog(string name, IDialogParameters parameters, DialogCallback callback)\n    {\n        IDialogContainer? dialogModal = null;\n        try\n        {\n            parameters = UriParsingHelper.GetSegmentParameters(name, parameters ?? new DialogParameters());\n\n            var currentPage = GetCurrentPage();\n            ArgumentNullException.ThrowIfNull(currentPage);\n            var container = currentPage.GetContainerProvider();\n            // This needs to be resolved when called as a Module could load any time\n            // and register new dialogs\n            var registry = container.Resolve<IDialogViewRegistry>();\n            var view = registry.CreateView(container, UriParsingHelper.GetSegmentName(name)) as View \n                ?? throw new ViewCreationException(name, ViewType.Dialog);\n\n            dialogModal = container.Resolve<IDialogContainer>();\n            var dialogAware = GetDialogController(view);\n\n            async Task DialogAware_RequestClose(IDialogResult outResult)\n            {\n                try\n                {\n                    var result = await CloseDialogAsync(outResult ?? new DialogResult(), currentPage, dialogModal);\n                    if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse)\n                    {\n                        return;\n                    }\n\n                    // DialogStack is updated when the container removes the overlay (e.g. DialogContainerPage.DoPop).\n                    await callback.Invoke(result);\n                    GC.Collect();\n                }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs#L13-L49","documentation":"DialogServiceBase.ShowDialog wraps any failure that occurs while constructing and showing a dialog (view creation, container resolution, controller wiring) in a DialogException with the message \"Error creating dialog '{name}'\". The view is created via IDialogViewRegistry; if the registered view cannot be created or any setup step fails, this aggregate exception surfaces the underlying cause as InnerException.","triggerScenarios":"Calling dialogService.ShowDialog(name, ...) where the dialog view registration throws (ViewCreationException), the DI container cannot resolve IDialogContainer/IDialogViewRegistry, the view's constructor throws, or required registrations are missing when a module loads lazily.","commonSituations":"Dialog registered with wrong view/viewModel pair; dialog view constructor has unresolvable constructor dependencies; module registrations not yet loaded when ShowDialog is invoked; typo in dialog name so registry returns null.","solutions":["Inspect InnerException for the root cause (often ViewCreationException or a DI resolution failure).","Verify the dialog is registered via container.RegisterDialog<view, viewModel>(name) and the name matches exactly.","Check that the dialog view's constructor dependencies are all registered in the container.","Ensure module registrations run before ShowDialog is called (register modules at app startup)."],"exampleFix":"// before\ncontainer.RegisterDialog<UnknownView, MyViewModel>();\n// after\ncontainer.RegisterDialog<MyDialogView, MyDialogViewModel>(\"MyDialog\");","handlingStrategy":"try-catch","validationCode":"if (!_container.IsRegistered<IDialogViewRegistry>() ||\n    !DialogNames.Contains(name))\n    throw new InvalidOperationException($\"Dialog '{name}' is not registered\");","typeGuard":null,"tryCatchPattern":"try { await dialogService.ShowDialogAsync(name); }\ncatch (DialogException ex) { logger.Error(ex.InnerException ?? ex, \"Dialog '{name}' failed to create\", name); }","preventionTips":["Register every dialog via container.RegisterDialog<view, viewModel>() at startup.","Keep dialog view constructors free of unregistered dependencies.","Verify dialog names with a startup smoke test that resolves each registered dialog."],"tags":["prism","maui","dialogs","dependency-injection"],"backgroundTag":"api-error-response","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}