dotnet/wpf · error · InvalidOperationException
Microsoft.Windows.Controls.SR.ResizeParametersNotValid
Error message
Microsoft.Windows.Controls.SR.ResizeParametersNotValid
What it means
Resize throws InvalidOperationException(SR.ResizeParametersNotValid) when RibbonMenuItem.ResizePopupInternal(width, height) returns false — i.e. the passed dimensions were rejected by the menu item's internal popup sizing logic even though CanResize was true and dimensions were positive. It signals the resize could not be applied to the popup.
Solutions
- Pass dimensions within the popup's realistic min/max size range (measure the popup's constraints first)
- Ensure the submenu popup is fully open before resizing
- Catch InvalidOperationException and retry with the popup's current size as a baseline
- Fall back to resizing via the RibbonMenu's own layout properties instead of UIA
Example fix
// before
transformPattern.Resize(1, 1); // likely rejected by ResizePopupInternal
// after
var target = new Size(Math.Max(minWidth, w), Math.Max(minHeight, h));
if (transformPattern.Current.CanResize)
{
transformPattern.Resize(target.Width, target.Height);
} Defensive patterns
Strategy: try-catch
Validate before calling
bool sizeOk = width > 0 && height > 0 && width <= menuItem.MaxPopupWidth && height <= menuItem.MaxPopupHeight; // within popup constraints
Type guard
bool IsWithinPopupBounds(double w, double h) => w > 0 && h > 0 && w <= popup.MaxWidth && h <= popup.MaxHeight;
Try / catch
try { transformPattern.Resize(w, h); } catch (InvalidOperationException) { var s = currentPopupSize; transformPattern.Resize(s.Width, s.Height + delta); } Prevention
- Stay within the popup's min/max layout constraints
- Resize only while the submenu popup is fully open
- Start from the popup's current size and adjust incrementally
When it happens
Trigger: TransformPattern.Resize(w,h) on a valid, checkable RibbonMenuItem where ResizePopupInternal fails — e.g. dimensions incompatible with the popup's layout constraints, popup not open, or sizes exceeding/falling below internal min/max popup bounds.
Common situations: UIA tests probing extreme popup sizes; resizing while the submenu popup is closing; gallery/dropdown popups whose layout cannot honor the requested size.
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
- ResizeParametersNotValid
- ' ' must be the root element of a tree, but has a logical…
- ArgumentOutOfRangeException
- Cannot reopen a popup in the closed event handler.
- ElementNotAvailableException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/50f5e115da436eb6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonMenuItemDataAutomationPeer.cs:353
UIElement owner = GetWrapper();
if (owner == null)
{
throw new ElementNotAvailableException(Microsoft.Windows.Controls.SR.VirtualizedElement);
}
RibbonMenuItem menuItemOwner = owner as RibbonMenuItem;
if (menuItemOwner == null)
{
throw new InvalidOperationException(Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed);
}
if (!((ITransformProvider)this).CanResize || width <= 0 || height <= 0)
throw new InvalidOperationException(Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed);
if (!menuItemOwner.ResizePopupInternal(width, height))
{
throw new InvalidOperationException(Microsoft.Windows.Controls.SR.ResizeParametersNotValid);
}
}
void ITransformProvider.Rotate(double degrees)
{
throw new InvalidOperationException(Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed);
}
#endregion
#if !RIBBON_IN_FRAMEWORK
#region Private methods
private UIElement GetWrapper()
{
UIElement wrapper = null;
ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer;
if (itemsControlAutomationPeer != null)View on GitHub (pinned to 81131a70a4)