{"record":{"id":"6747a52d33e21ed3","repo":"dotnet/wpf","slug":"sr-peoplepickerinvalidparentwindow","errorCode":null,"errorMessage":"SR.PeoplePickerInvalidParentWindow","messagePattern":"SR\\.PeoplePickerInvalidParentWindow","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs","lineNumber":274,"sourceCode":"            return addresses.ToArray();\n        }\n\n        /// <summary>\n        /// Verifies that the given parent HWND is either null or an RMPublishingDialog \n        /// Windows Form.\n        /// </summary>\n        /// <param name=\"hWndParent\"></param>\n        /// \n        private void ValidateHWnd(IntPtr hWndParent)\n        {\n            if( hWndParent != IntPtr.Zero )\n            {\n                System.Windows.Forms.Control rmPublishingDialog = \n                    System.Windows.Forms.Control.FromHandle(hWndParent) as RMPublishingDialog;\n\n                if (rmPublishingDialog == null)\n                {\n                    throw new InvalidOperationException(SR.PeoplePickerInvalidParentWindow);\n                }\n            }            \n        }\n\n        #endregion Private Methods\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n        #region Private Fields\n\n        //The key name for the ActiveDirectory E-Mail address property\n        private const String _adEmailAddressKey = \"mail\";\n\n        #region DsObjectNamesWrapper Class\n","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs#L256-L292","documentation":"PeoplePickerWrapper.ValidateHWnd requires that the parent window handle belongs to an RMPublishingDialog WinForms control; if Control.FromHandle(hWndParent) is not an RMPublishingDialog, it throws InvalidOperationException(SR.PeoplePickerInvalidParentWindow). The people-picker must be parented to the RMS publishing dialog.","triggerScenarios":"Calling PeoplePickerWrapper.Show (or the wrapper's ShowDialog path) with an hWndParent that is null/foreign or points to a window that is not the RMPublishingDialog.","commonSituations":"Hosting the people picker from a custom WPF window or after the publishing dialog was already closed (handle destroyed), so FromHandle returns null or another control type.","solutions":["Pass the RMPublishingDialog's handle as the parent — always call the picker from within the RMS publishing dialog flow.","Ensure the parent dialog is still alive/shown when calling Show (check IsHandleCreated/IsDisposed first).","If custom UI is needed, host the picker inside an RMPublishingDialog rather than an arbitrary window."],"exampleFix":"// before\npickerWrapper.Show(customWindow.Handle);\n// after\nif (publishingDialog.IsHandleCreated && !publishingDialog.IsDisposed)\n    pickerWrapper.Show(publishingDialog.Handle);\nelse\n    throw new InvalidOperationException(\"RMS publishing dialog must be open to show people picker.\");","handlingStrategy":"validation","validationCode":"if (parentDialog == null || parentDialog.IsDisposed || !parentDialog.IsHandleCreated)\n    throw new InvalidOperationException(\"RMPublishingDialog must be alive to host the people picker.\");","typeGuard":"bool IsValidPickerParent(IntPtr hWnd) => System.Windows.Forms.Control.FromHandle(hWnd) is RMPublishingDialog;","tryCatchPattern":"try { peoplePickerWrapper.Show(parentHandle); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"InvalidParentWindow\"))\n{ Log.Error(\"People picker shown without RMPublishingDialog parent\", ex); }","preventionTips":["Only call Show from inside the RMS publishing dialog flow.","Check parent dialog lifetime/handle before Show.","Never pass arbitrary WPF window handles."],"tags":["wpf","rights-management","window-handle","interop"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}