{"record":{"id":"dc8e7b80f21500f2","repo":"AvaloniaUI/Avalonia","slug":"attempt-to-call-invalidatearrange-on-wrong-layoutm","errorCode":null,"errorMessage":"Attempt to call InvalidateArrange on wrong LayoutManager.","messagePattern":"Attempt to call InvalidateArrange on wrong LayoutManager\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Layout/LayoutManager.cs","lineNumber":98,"sourceCode":"\n            if (_disposed)\n            {\n                return;\n            }\n\n            if (!control.IsAttachedToVisualTree)\n            {\n#if DEBUG\n                throw new AvaloniaInternalException(\n                    \"LayoutManager.InvalidateArrange called on a control that is detached from the visual tree.\");\n#else\n                return;\n#endif\n            }\n\n            if (control.GetLayoutRoot() != _owner)\n            {\n                throw new ArgumentException(\"Attempt to call InvalidateArrange on wrong LayoutManager.\");\n            }\n\n            _toArrange.Enqueue(control);\n            QueueLayoutPass();\n        }\n\n        internal void ExecuteQueuedLayoutPass()\n        {\n            if (!_queued)\n            {\n                return;\n            }\n            \n            ExecuteLayoutPass();\n        }\n\n        /// <inheritdoc/>\n        public virtual void ExecuteLayoutPass()","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Layout/LayoutManager.cs#L80-L116","documentation":"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.","triggerScenarios":"Calling layoutManager.InvalidateArrange(control) where control.GetLayoutRoot() != layoutManager._owner. Same cross-root condition as the measure variant.","commonSituations":"Same as the measure variant: reparenting between top-level windows, stale manager references, popups/overlays with separate roots.","solutions":["Call control.InvalidateArrange() directly so the control routes through its own layout root's manager.","Ensure controls are properly detached/attached during reparenting.","Do not hold LayoutManager references that outlive a control's membership in a given visual tree."],"exampleFix":"// before\n_someSharedLayoutManager.InvalidateArrange(myControl);\n\n// after\nmyControl.InvalidateArrange();","handlingStrategy":"validation","validationCode":"// Always invalidate through the control itself\n// control.InvalidateArrange() routes to the correct manager.\nif (control.GetLayoutRoot() == layoutManagerOwner)\n    layoutManager.InvalidateArrange(control);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer control.InvalidateArrange() over direct LayoutManager calls.","Do not hold LayoutManager references that outlive a control's tree membership.","Ensure controls are fully detached before re-attaching elsewhere."],"tags":["layout","layout-manager","visual-tree","reparenting"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}