{"record":{"id":"37e2f66ddebec635","repo":"dotnet/wpf","slug":"sr-cantshowmbservicewithowner","errorCode":null,"errorMessage":"SR.CantShowMBServiceWithOwner","messagePattern":"SR\\.CantShowMBServiceWithOwner","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MessageBox.cs","lineNumber":397,"sourceCode":"            {\n                throw new InvalidEnumArgumentException (\"defaultResult\", (int)defaultResult, typeof(MessageBoxResult));\n            }\n            if (!IsValidMessageBoxOptions(options))\n            {\n                throw new InvalidEnumArgumentException(\"options\", (int)options, typeof(MessageBoxOptions));\n            }\n\n            // UserInteractive??\n            //\n            /*if (!SystemInformation.UserInteractive && (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0) {\n                throw new InvalidOperationException(\"UNDONE: SR.GetString(SR.CantShowModalOnNonInteractive)\");\n            }*/\n\n            if ( (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0)\n            {\n                if (owner != IntPtr.Zero)\n                {\n                    throw new ArgumentException(SR.CantShowMBServiceWithOwner);\n                }\n            }\n            else\n            {\n                if (owner == IntPtr.Zero)\n                {\n                    owner = UnsafeNativeMethods.GetActiveWindow();\n                }\n            }\n\n            int style = (int) button | (int) icon | (int) DefaultResultToButtonNumber(defaultResult, button) | (int) options;\n\n            // modal dialog notification?\n            //\n            //Application.BeginModalMessageLoop();\n            //MessageBoxResult result = Win32ToMessageBoxResult(SafeNativeMethods.MessageBox(new HandleRef(owner, handle), messageBoxText, caption, style));\n            MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));\n            // modal dialog notification?","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MessageBox.cs#L379-L415","documentation":"MessageBox.ShowCore throws ArgumentException when options includes ServiceNotification or DefaultDesktopOnly while an owner window handle (ownerWindow != IntPtr.Zero) is supplied. Service-notification dialogs go to the desktop/service context and cannot have an owner window.","triggerScenarios":"Calling MessageBox.Show(Window owner, ...) or an overload passing ownerWindow with options set to MessageBoxOptions.ServiceNotification or MessageBoxOptions.DefaultDesktopOnly.","commonSituations":"Adding service-notification flags to an existing Show call that already passes a WPF window owner; copy-pasted options from a service codebase into UI code.","solutions":["Remove the ServiceNotification/DefaultDesktopOnly flags when an owner window is present, or drop the owner parameter.","Use two code paths: owner-based normal dialogs, and ownerless service-notification calls (MessageBox.Show with owner IntPtr.Zero).","If you need both, branch on the flags before calling Show and clear the conflicting owner."],"exampleFix":"// before\nMessageBox.Show(ownerWindow, msg, title, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);\n// after\n// owner-based: no service flags\nMessageBox.Show(ownerWindow, msg, title, MessageBoxButton.OK, MessageBoxImage.Warning);\n// or service notification: no owner\nMessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);","handlingStrategy":"validation","validationCode":"bool isService = (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0;\nif (isService && ownerWindow != IntPtr.Zero) options &= ~(MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly);","typeGuard":"bool CanUseOwner(MessageBoxOptions o) => (o & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0;","tryCatchPattern":"try { MessageBox.Show(ownerWindow, msg, title, button, icon, result, options); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ServiceNotification\") || ex.Message.Contains(\"owner\")) { MessageBox.Show(msg, title, button, icon, result, options & ~(MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)); }","preventionTips":["Never combine an owner window with ServiceNotification/DefaultDesktopOnly","Branch before Show: service notifications go ownerless, UI dialogs keep their owner","Centralize MessageBox.Show in a helper that enforces this rule"],"tags":["wpf","messagebox","argument-exception","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}