{"record":{"id":"5532700657e22451","repo":"AvaloniaUI/Avalonia","slug":"invalid-arrange-rectangle","errorCode":null,"errorMessage":"Invalid Arrange rectangle.","messagePattern":"Invalid Arrange rectangle\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Layout/Layoutable.cs","lineNumber":419,"sourceCode":"\n                Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, \"Measure requested {DesiredSize}\", DesiredSize);\n\n                if (DesiredSize != previousDesiredSize)\n                {\n                    this.GetVisualParent<Layoutable>()?.ChildDesiredSizeChanged(this);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Arranges the control and its children.\n        /// </summary>\n        /// <param name=\"rect\">The control's new bounds.</param>\n        public void Arrange(Rect rect)\n        {\n            if (IsInvalidRect(rect))\n            {\n                throw new InvalidOperationException(\"Invalid Arrange rectangle.\");\n            }\n\n            if (!IsMeasureValid)\n            {\n                Measure(_previousMeasure ?? rect.Size);\n            }\n\n            if (!IsArrangeValid || _previousArrange != rect)\n            {\n                using var activity = Diagnostic.ArrangingLayoutable()?\n                    .AddTag(Diagnostic.Tags.Control, this);\n\n                Logger.TryGet(LogEventLevel.Verbose, LogArea.Layout)?.Log(this, \"Arrange to {Rect} \", rect);\n\n                IsArrangeValid = true;\n                ArrangeCore(rect);\n                _previousArrange = rect;\n            }","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Layout/Layoutable.cs#L401-L437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar rect = new Rect(x, y, available.Width - childWidth, available.Height);\nchild.Arrange(rect);\n\n// after\nvar w = Math.Max(0, available.Width - childWidth);\nvar h = Math.Max(0, available.Height);\nchild.Arrange(new Rect(x, y, w, h));","handlingStrategy":"validation","validationCode":"static Rect ValidArrange(Rect r) => new Rect(r.X, r.Y,\n    Math.Max(0, r.Width), Math.Max(0, r.Height));\n\nchild.Arrange(ValidArrange(rect));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["layout","arrange","custom-panel","nan"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}