{"record":{"id":"5db523db1c50ce68","repo":"dotnet/wpf","slug":"sr-uielement-layout-infinityarrange","errorCode":null,"errorMessage":"SR.UIElement_Layout_InfinityArrange","messagePattern":"SR\\.UIElement_Layout_InfinityArrange","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs","lineNumber":799,"sourceCode":"            try\n            {\n                //             VerifyAccess();\n\n                // Disable reentrancy during the arrange pass.  This is because much work is done\n                // during arrange - such as formatting PTS stuff, creating\n                // fonts, etc.  Generally speaking, we cannot survive reentrancy in these code\n                // paths.\n                using (Dispatcher.DisableProcessing())\n                {\n                    //enforce that Arrange can not come with Infinity size or NaN\n                    if (double.IsPositiveInfinity(finalRect.Width)\n                        || double.IsPositiveInfinity(finalRect.Height)\n                        || double.IsNaN(finalRect.Width)\n                        || double.IsNaN(finalRect.Height)\n                      )\n                    {\n                        DependencyObject parent = GetUIParent() as UIElement;\n                        throw new InvalidOperationException(\n                            SR.Format(\n                                SR.UIElement_Layout_InfinityArrange,\n                                    (parent == null ? \"\" : parent.GetType().FullName),\n                                    this.GetType().FullName));\n                    }\n\n\n                    //if Collapsed, we should not Arrange, keep dirty bit but remove request\n                    if (this.Visibility == Visibility.Collapsed\n                        || ((Visual)this).CheckFlagsAnd(VisualFlags.IsLayoutSuspended))\n                    {\n                        //reset arrange request.\n                        if (ArrangeRequest != null)\n                            ContextLayoutManager.From(Dispatcher).ArrangeQueue.Remove(this);\n\n                        //  remember though that parent tried to arrange at this rect\n                        //  in case when later this element is called to arrange incrementally\n                        //  it has up-to-date information stored in _finalRect","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs#L781-L817","documentation":"UIElement.Arrange throws an InvalidOperationException (SR.UIElement_Layout_InfinityArrange, formatted with the parent's and element's type names) when finalRect contains PositiveInfinity or NaN in width/height. Arrange requires a finite rectangle; the message names the parent whose layout produced the bad rect.","triggerScenarios":"A parent panel passing an infinite/NaN finalRect to child.Arrange(...), typically because its own measure or available size was infinite; custom ArrangeOverride implementations forwarding infinite finalSize.","commonSituations":"Custom panels arranging children in infinite scroll/viewport scenarios without clamping; elements inside ScrollViewer whose ArrangeOverride passes raw unbounded sizes; broken custom layouts after refactor.","solutions":["In the parent's ArrangeOverride, clamp finalRect dimensions to finite values before calling child.Arrange.","Ensure MeasureOverride returns finite sizes so Arrange inherits sane constraints.","For unbounded content, use scroll-aware patterns (ScrollViewer + finite viewport math) instead of passing infinity."],"exampleFix":"// before\nchild.Arrange(new Rect(point, finalSize)); // finalSize may be infinite\n// after\nvar w = double.IsInfinity(finalSize.Width) ? child.DesiredSize.Width : finalSize.Width;\nvar h = double.IsInfinity(finalSize.Height) ? child.DesiredSize.Height : finalSize.Height;\nchild.Arrange(new Rect(point, new Size(w, h)));","handlingStrategy":"validation","validationCode":"if (double.IsInfinity(finalRect.Width) || double.IsInfinity(finalRect.Height) || double.IsNaN(finalRect.Width) || double.IsNaN(finalRect.Height))\n    finalRect = new Rect(finalRect.Location, new Size(child.DesiredSize.Width, child.DesiredSize.Height));","typeGuard":"bool IsValidArrangeRect(Rect r) => double.IsFinite(r.Width) && double.IsFinite(r.Height) && !double.IsNaN(r.Width) && !double.IsNaN(r.Height);","tryCatchPattern":"try { child.Arrange(finalRect); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Arrange\")) { /* clamp rect and retry */ }","preventionTips":["Always clamp arrange rects to finite values in ArrangeOverride","Ensure measure results are finite so arrange inherits sane sizes","Handle ScrollViewer unbounded constraints explicitly"],"tags":["wpf","layout","arrange"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}