dotnet/wpf · error · InvalidOperationException

SR.PeoplePickerInvalidParentWindow

Error message

SR.PeoplePickerInvalidParentWindow

What it means

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.

Solutions

  1. Pass the RMPublishingDialog's handle as the parent — always call the picker from within the RMS publishing dialog flow.
  2. Ensure the parent dialog is still alive/shown when calling Show (check IsHandleCreated/IsDisposed first).
  3. If custom UI is needed, host the picker inside an RMPublishingDialog rather than an arbitrary window.

Example fix

// before
pickerWrapper.Show(customWindow.Handle);
// after
if (publishingDialog.IsHandleCreated && !publishingDialog.IsDisposed)
    pickerWrapper.Show(publishingDialog.Handle);
else
    throw new InvalidOperationException("RMS publishing dialog must be open to show people picker.");
Defensive patterns

Strategy: validation

Validate before calling

if (parentDialog == null || parentDialog.IsDisposed || !parentDialog.IsHandleCreated)
    throw new InvalidOperationException("RMPublishingDialog must be alive to host the people picker.");

Type guard

bool IsValidPickerParent(IntPtr hWnd) => System.Windows.Forms.Control.FromHandle(hWnd) is RMPublishingDialog;

Try / catch

try { peoplePickerWrapper.Show(parentHandle); }
catch (InvalidOperationException ex) when (ex.Message.Contains("InvalidParentWindow"))
{ Log.Error("People picker shown without RMPublishingDialog parent", ex); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/6747a52d33e21ed3. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/PeoplePickerWrapper.cs:274

            return addresses.ToArray();
        }

        /// <summary>
        /// Verifies that the given parent HWND is either null or an RMPublishingDialog 
        /// Windows Form.
        /// </summary>
        /// <param name="hWndParent"></param>
        /// 
        private void ValidateHWnd(IntPtr hWndParent)
        {
            if( hWndParent != IntPtr.Zero )
            {
                System.Windows.Forms.Control rmPublishingDialog = 
                    System.Windows.Forms.Control.FromHandle(hWndParent) as RMPublishingDialog;

                if (rmPublishingDialog == null)
                {
                    throw new InvalidOperationException(SR.PeoplePickerInvalidParentWindow);
                }
            }            
        }

        #endregion Private Methods

        //------------------------------------------------------
        //
        //  Private Fields
        //
        //------------------------------------------------------
        #region Private Fields

        //The key name for the ActiveDirectory E-Mail address property
        private const String _adEmailAddressKey = "mail";

        #region DsObjectNamesWrapper Class

View on GitHub (pinned to 81131a70a4)