AvaloniaUI/Avalonia · error · ArgumentException

Attempt to call InvalidateArrange on wrong LayoutManager.

Error message

Attempt to call InvalidateArrange on wrong LayoutManager.

What it means

InvalidateArrange throws under the same wrong-manager condition as InvalidateMeasure, but for the arrange pass. The LayoutManager verifies that the control's GetLayoutRoot() matches its owner before enqueueing an arrange invalidation; a mismatch means the control lives in a different visual tree root and cannot be arranged by this manager.

Source

Thrown at src/Avalonia.Base/Layout/LayoutManager.cs:98

            if (_disposed)
            {
                return;
            }

            if (!control.IsAttachedToVisualTree)
            {
#if DEBUG
                throw new AvaloniaInternalException(
                    "LayoutManager.InvalidateArrange called on a control that is detached from the visual tree.");
#else
                return;
#endif
            }

            if (control.GetLayoutRoot() != _owner)
            {
                throw new ArgumentException("Attempt to call InvalidateArrange on wrong LayoutManager.");
            }

            _toArrange.Enqueue(control);
            QueueLayoutPass();
        }

        internal void ExecuteQueuedLayoutPass()
        {
            if (!_queued)
            {
                return;
            }
            
            ExecuteLayoutPass();
        }

        /// <inheritdoc/>
        public virtual void ExecuteLayoutPass()

View on GitHub (pinned to 11c5427268)

Solutions

  1. Call control.InvalidateArrange() directly so the control routes through its own layout root's manager.
  2. Ensure controls are properly detached/attached during reparenting.
  3. Do not hold LayoutManager references that outlive a control's membership in a given visual tree.

Example fix

// before
_someSharedLayoutManager.InvalidateArrange(myControl);

// after
myControl.InvalidateArrange();
Defensive patterns

Strategy: validation

Validate before calling

// Always invalidate through the control itself
// control.InvalidateArrange() routes to the correct manager.
if (control.GetLayoutRoot() == layoutManagerOwner)
    layoutManager.InvalidateArrange(control);

Prevention

When it happens

Trigger: Calling layoutManager.InvalidateArrange(control) where control.GetLayoutRoot() != layoutManager._owner. Same cross-root condition as the measure variant.

Common situations: Same as the measure variant: reparenting between top-level windows, stale manager references, popups/overlays with separate roots.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/dc8e7b80f21500f2. Report an issue: GitHub.