{"record":{"id":"aee9c50fae346156","repo":"dotnet/wpf","slug":"sr-documentgridvisualtreeoutofsync","errorCode":null,"errorMessage":"SR.DocumentGridVisualTreeOutOfSync","messagePattern":"SR\\.DocumentGridVisualTreeOutOfSync","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs","lineNumber":1189,"sourceCode":"            //1 which is our first page.\n            int visualChild = _firstPageVisualIndex;\n\n            //Now walk through the visible rows and arrange the pages therein.\n            for (int row = _firstVisibleRow; row < _firstVisibleRow + _visibleRowCount; row++)\n            {\n                //Calculate the position for this row.\n                CalculateRowOffsets(row, out xOffset, out yOffset);\n\n                //Get the current row.\n                RowInfo currentRow = _rowCache.GetRow(row);\n\n                //Now we can lay out this row.\n                for (int page = currentRow.FirstPage; page < currentRow.FirstPage + currentRow.PageCount; page++)\n                {\n                    //This should never, ever happen so we'll throw if it does.\n                    if (visualChild > _childrenCollection.Count - 1)\n                    {\n                        throw new InvalidOperationException(SR.DocumentGridVisualTreeOutOfSync);\n                    }\n\n                    //Get the cached size of this page.\n                    Size pageSize = _pageCache.GetPageSize(page);\n\n                    //Scale it by our scale factor\n                    pageSize.Width *= Scale;\n                    pageSize.Height *= Scale;\n\n                    //Arrange the page if necessary\n                    UIElement uiPage = _childrenCollection[visualChild] as UIElement;\n                    if (uiPage != null)\n                    {\n                        Point pageOffset;\n                        //Move the page to the right place based on the FlowDirection of the content.\n                        if (_pageCache.IsContentRightToLeft)\n                        {\n                            pageOffset = new Point(Math.Max(ViewportWidth, ExtentWidth) - (xOffset + pageSize.Width), yOffset);","sourceCodeStart":1171,"sourceCodeEnd":1207,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs#L1171-L1207","documentation":"InvalidOperationException from DocumentGrid.ArrangeOverride: the row cache and the visual tree have diverged (e.g. the row layout was recomputed between Measure and Arrange, or the visible-row bookkeeping no longer matches the child visuals). The throw is an internal consistency check during page arrangement.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:1189 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Avoid changing pagination, scale, or content between the measure and arrange passes (e.g. in ArrangeOverride overrides or bindings)","Ensure InvalidateMeasure is called rather than mutating the row cache directly when document state changes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}