{"record":{"id":"910ffcea4cc6f676","repo":"PrismLibrary/Prism","slug":"a-dialog-s-content-must-be-a-frameworkelement","errorCode":null,"errorMessage":"A dialog's content must be a FrameworkElement","messagePattern":"A dialog's content must be a FrameworkElement","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/Uno/Prism.Uno/Dialogs/DialogService.cs","lineNumber":59,"sourceCode":"                var str = ex.ToString();\n                await callback.Invoke(ex);\n            }\n        }\n\n        IDialogWindow CreateDialogWindow(string? name)\n        {\n            if (string.IsNullOrWhiteSpace(name))\n                return _containerProvider.Resolve<IDialogWindow>();\n            else\n                return _containerProvider.Resolve<IDialogWindow>(name);\n        }\n\n        void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters)\n        {\n            var content = _containerProvider.Resolve<object>(dialogName);\n            if (content is not FrameworkElement dialogContent)\n            {\n                throw new NullReferenceException(\"A dialog's content must be a FrameworkElement\");\n            }\n\n            MvvmHelpers.AutowireViewModel(content);\n\n            if (dialogContent.DataContext is not IDialogAware viewModel)\n            {\n                throw new NullReferenceException($\"A dialog's ViewModel must implement the IDialogAware interface ({dialogContent.DataContext})\");\n            }\n\n            DialogService.ConfigureDialogWindowProperties(window, dialogContent, viewModel);\n\n            MvvmHelpers.ViewAndViewModelAction<IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));\n        }\n\n        void ConfigureDialogWindowEvents(IDialogWindow contentDialog, DialogCallback callback)\n        {\n            IDialogResult? result = null;\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Uno/Prism.Uno/Dialogs/DialogService.cs#L41-L77","documentation":"Prism's Uno DialogService resolves the view registered for the dialog name and requires the resolved object to be a FrameworkElement so it can wire up the dialog window content. If the container resolves anything else (or null), it throws this NullReferenceException. This is a registration/usage contract: dialogs must be registered as views (FrameworkElement-based) for dialog service lookups to succeed.","triggerScenarios":"Calling IDialogService.ShowDialog(name, ...) where the type registered under `name` in the container (via RegisterDialog or container registration) is not a FrameworkElement, or resolving an unregistered name returns null/non-FrameworkElement.","commonSituations":"Registering a ViewModel (or plain class) instead of a View with RegisterDialog; forgetting to call RegisterDialog and having a stale/incorrect container registration; a custom registration that maps the dialog name to a non-UI type; migration from another container where Resolve<object>(name) semantics differ.","solutions":["Register the dialog view with RegisterDialog<MyDialogView, MyDialogViewModel>(\"name\") so Resolve<object>(name) yields a FrameworkElement.","Ensure the dialog name passed to ShowDialog matches the registered name exactly.","Make the dialog a UserControl (or other FrameworkElement) rather than a plain class or ViewModel.","Verify the dialog module/assembly is actually loaded and registered before ShowDialog is called (initialize the module first)."],"exampleFix":"// before\ncontainerRegistry.RegisterDialog<MyDialogViewModel>(); // resolves a non-FrameworkElement\n\n// after\ncontainerRegistry.RegisterDialog<MyDialogView, MyDialogViewModel>();","handlingStrategy":"type-guard","validationCode":"// before calling ShowDialog\nvar content = containerProvider.Resolve<object>(dialogName);\nif (content is not FrameworkElement)\n    throw new InvalidOperationException($\"Dialog '{dialogName}' must be registered as a FrameworkElement view.\");","typeGuard":"static bool IsRegisteredDialogView(IContainerProvider container, string name) =>\n    container.Resolve<object>(name) is FrameworkElement;","tryCatchPattern":"try\n{\n    dialogService.ShowDialog(dialogName, parameters, callback);\n}\ncatch (NullReferenceException ex) when (ex.Message.Contains(\"must be a FrameworkElement\"))\n{\n    logger.LogError(ex, \"Dialog {Dialog} not registered as a view\", dialogName);\n}","preventionTips":["Always register dialogs with RegisterDialog<View, ViewModel>()","Keep dialog names as constants shared between registration and ShowDialog calls","Add a unit test that resolves every registered dialog name and asserts it is a FrameworkElement","Never register ViewModels as dialogs"],"tags":["prism","uno","dialogs","registration","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}