AvaloniaUI/Avalonia · error · InvalidOperationException
Invalid Arrange rectangle.
Error message
Invalid Arrange rectangle.
What it means
Arrange throws when the supplied Rect has a negative or non-finite Width/Height, or a non-finite X/Y. Layout positions and sizes must be finite and non-negative in size; an invalid arrange rectangle would place the control at an uncomputable position or give it an impossible area. Note X/Y may be any finite value (including negative offset) but Width/Height must be >= 0 and finite.
Source
Thrown at src/Avalonia.Base/Layout/Layoutable.cs:419
Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Measure requested {DesiredSize}", DesiredSize);
if (DesiredSize != previousDesiredSize)
{
this.GetVisualParent<Layoutable>()?.ChildDesiredSizeChanged(this);
}
}
}
/// <summary>
/// Arranges the control and its children.
/// </summary>
/// <param name="rect">The control's new bounds.</param>
public void Arrange(Rect rect)
{
if (IsInvalidRect(rect))
{
throw new InvalidOperationException("Invalid Arrange rectangle.");
}
if (!IsMeasureValid)
{
Measure(_previousMeasure ?? rect.Size);
}
if (!IsArrangeValid || _previousArrange != rect)
{
using var activity = Diagnostic.ArrangingLayoutable()?
.AddTag(Diagnostic.Tags.Control, this);
Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, "Arrange to {Rect} ", rect);
IsArrangeValid = true;
ArrangeCore(rect);
_previousArrange = rect;
}View on GitHub (pinned to 11c5427268)
Solutions
- Clamp width and height to >= 0 and ensure all components are finite before calling Arrange.
- Verify the arrange rect is within sensible bounds in ArrangeOverride: use new Rect(x, y, Math.Max(0, w), Math.Max(0, h)).
- Check upstream measure results feeding into arrange math.
Example fix
// before var rect = new Rect(x, y, available.Width - childWidth, available.Height); child.Arrange(rect); // after var w = Math.Max(0, available.Width - childWidth); var h = Math.Max(0, available.Height); child.Arrange(new Rect(x, y, w, h));
Defensive patterns
Strategy: validation
Validate before calling
static Rect ValidArrange(Rect r) => new Rect(r.X, r.Y,
Math.Max(0, r.Width), Math.Max(0, r.Height));
child.Arrange(ValidArrange(rect)); Prevention
- In ArrangeOverride, clamp width/height to >= 0 and ensure positions are finite.
- Verify child.DesiredSize feeds are sane before computing final rects.
- Unit-test custom panels with zero/negative available space.
When it happens
Trigger: Calling control.Arrange(rect) where rect.Width or rect.Height is negative, NaN, or Infinity, or where rect.X/rect.Y is NaN or Infinity. Common in custom panels computing final rects from measure results that went bad.
Common situations: Custom panel ArrangeOverride computing a rect with negative width (e.g. child.DesiredSize.Width minus something larger). Passing a rect built from an unset/uninitialized point. Arithmetic overflow or division producing Infinity.
Related errors
- Cannot call Measure using a size with NaN values.
- 'MaxTextHeight' property value cannot be NaN.
- The control isn't currently attached to a toplevel
- Invalid render scaling value {scaling}
- Attempt to call InvalidateMeasure on wrong LayoutManager.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/5532700657e22451.
Report an issue: GitHub.