{"record":{"id":"6a62b574e3230d72","repo":"lepoco/wpfui","slug":"cannot-set-dialoghost-when-dialoghostex-is-already","errorCode":null,"errorMessage":"Cannot set DialogHost when DialogHostEx is already set.","messagePattern":"Cannot set DialogHost when DialogHostEx is already set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs","lineNumber":626,"sourceCode":"    // Legacy and new host coexist for compatibility during migration.\n    private ContentPresenter? _dialogHost;\n    private ContentDialogHost? _dialogHostEx;\n\n    /// <summary>\n    /// Gets or sets <see cref=\"DialogHost\"/> inside of which the dialogue will be placed.\n    /// </summary>\n    /// <exception cref=\"InvalidOperationException\">\n    /// Thrown if trying to set DialogHost when DialogHostEx is already set, or if trying to change DialogHost while the dialog is being shown.\n    /// </exception>\n    [Obsolete(\"DialogHost is deprecated. Please use DialogHostEx instead.\")]\n    public ContentPresenter? DialogHost\n    {\n        get => _dialogHost;\n        set\n        {\n            if (_dialogHostEx is not null)\n            {\n                throw new InvalidOperationException(\n                    \"Cannot set DialogHost when DialogHostEx is already set.\"\n                );\n            }\n\n            if (IsShowing)\n            {\n                throw new InvalidOperationException(\n                    \"Cannot change DialogHost while the dialog is being shown.\"\n                );\n            }\n\n            if (ReferenceEquals(_dialogHost, value))\n            {\n                return;\n            }\n\n            if (_dialogHost is not null)\n            {","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs#L608-L644","documentation":"Thrown by the DialogHost property setter (deprecated) when the new-style DialogHostEx is already set on the same ContentDialog. The control forbids assigning both host types to prevent ambiguous rendering, so setting the legacy host after DialogHostEx is rejected.","triggerScenarios":"Assigning ContentDialog.DialogHost = someContentPresenter after ContentDialog.DialogHostEx has already been assigned (or vice-versa guard at error 19). The _dialogHostEx field is non-null at set time.","commonSituations":"Migrating from the legacy ContentPresenter host to ContentDialogHost but leaving XAML/code that still assigns DialogHost; or shared dialog instances receiving both host assignments from different code paths.","solutions":["Standardize on DialogHostEx and remove all assignments to the deprecated DialogHost property.","Search for DialogHost = (CS0618 obsolete) usages and migrate them to DialogHostEx.","Ensure only one host assignment path runs per dialog instance."],"exampleFix":"// before\ndialog.DialogHost = myContentPresenter; // DialogHostEx already set\n\n// after\ndialog.DialogHostEx = myContentDialogHost;","handlingStrategy":"validation","validationCode":"if (dialog.DialogHostEx is null) { dialog.DialogHost = presenter; }","typeGuard":"static bool CanSetLegacyHost(ContentDialog d) => d.DialogHostEx is null && !d.IsShowing;","tryCatchPattern":null,"preventionTips":["Use DialogHostEx exclusively; remove deprecated DialogHost assignments.","Resolve CS0618 warnings to surface legacy host code.","Keep one host assignment path per dialog."],"tags":["content-dialog","host","api-migration","obsolete"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}