{"record":{"id":"a31dce17b7b21e33","repo":"lepoco/wpfui","slug":"use-nameof-showdialogasync-instead","errorCode":null,"errorMessage":"Use {nameof(ShowDialogAsync)} instead","messagePattern":"Use (.+?) instead","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui/Controls/MessageBox/MessageBox.cs","lineNumber":285,"sourceCode":"    {\n        Topmost = true;\n        SetValue(TemplateButtonCommandProperty, new RelayCommand<MessageBoxButton>(OnButtonClick));\n\n        PreviewMouseDoubleClick += static (_, args) => args.Handled = true;\n\n        Loaded += static (sender, _) =>\n        {\n            var self = (MessageBox)sender;\n            self.OnLoaded();\n        };\n    }\n\n    protected TaskCompletionSource<MessageBoxResult>? Tcs { get; set; }\n\n    [Obsolete($\"Use {nameof(ShowDialogAsync)} instead\")]\n    public new void Show()\n    {\n        throw new InvalidOperationException($\"Use {nameof(ShowDialogAsync)} instead\");\n    }\n\n    [Obsolete($\"Use {nameof(ShowDialogAsync)} instead\")]\n    public new bool? ShowDialog()\n    {\n        throw new InvalidOperationException($\"Use {nameof(ShowDialogAsync)} instead\");\n    }\n\n    [Obsolete($\"Use {nameof(Close)} with MessageBoxResult instead\")]\n    public new void Close()\n    {\n        throw new InvalidOperationException($\"Use {nameof(Close)} with MessageBoxResult instead\");\n    }\n\n    /// <summary>\n    /// Displays a message box\n    /// </summary>\n    /// <returns><see cref=\"MessageBoxResult\"/></returns>","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui/Controls/MessageBox/MessageBox.cs#L267-L303","documentation":"MessageBox.Show() is hidden ('new') and hard-throws to forbid the legacy Window.Show entry point. WPF UI's MessageBox is task-driven (TaskCompletionSource) and must be opened via ShowDialogAsync, which wires up the result TCS, the title-bar/mica setup, and cancellation. Calling the base Show bypasses all of that, so the library blocks it.","triggerScenarios":"Calling messageBox.Show() — the no-arg instance method inherited from Window — on a WPF.UI MessageBox instance; reflection/automation invoking Show by name; porting code from System.Windows.MessageBox and forgetting to switch the call.","commonSituations":"Copy-paste from a WinForms / classic WPF sample that uses .Show(); code generation or a helper that calls Show on any Window-derived type; an older codebase being migrated to WPF UI's MessageBox.","solutions":["Replace messageBox.Show() with await messageBox.ShowDialogAsync(showAsDialog: false).","For a non-modal display, pass showAsDialog: false to ShowDialogAsync.","Search the codebase for '.Show()' on MessageBox instances and update each.","Treat the [Obsolete] attribute as a compile-time prompt — address it before runtime."],"exampleFix":"// before\nvar box = new MessageBox { Content = \"hi\" };\nbox.Show(); // throws\n\n// after\nvar box = new MessageBox { Content = \"hi\" };\nawait box.ShowDialogAsync(showAsDialog: false);","handlingStrategy":"validation","validationCode":"// Replace box.Show() with the task-based API:\nawait box.ShowDialogAsync(showAsDialog: false);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the [Obsolete] warning on Show() as a compile-time blocker.","Grep for '.Show()' over MessageBox instances during migration.","Update generic Window helpers to special-case WPF.UI MessageBox."],"tags":["wpf","messagebox","api-misuse","obsolete"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}