{"record":{"id":"a0a44b82865a9bfd","repo":"dotnet/wpf","slug":"sr-documentgridvisualtreecontainsnonuielement","errorCode":null,"errorMessage":"SR.DocumentGridVisualTreeContainsNonUIElement","messagePattern":"SR\\.DocumentGridVisualTreeContainsNonUIElement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs","lineNumber":1217,"sourceCode":"                    //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);\n                        }\n                        else\n                        {\n                            pageOffset = new Point(xOffset, yOffset);\n                        }\n                        uiPage.Arrange(new Rect(pageOffset, pageSize));\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.DocumentGridVisualTreeContainsNonUIElement);\n                    }\n\n                    //Increment our horizontal offset to point to where the next page should go.\n                    xOffset += (pageSize.Width + HorizontalPageSpacing);\n\n                    //Move to the next page.\n                    visualChild++;\n                }\n            }\n\n            // As we scroll we need to keep the AdornerLayer up-to-date.\n            // This ensures that annotation components scroll with the content.\n            AdornerLayer layer = AdornerLayer.GetAdornerLayer(this);\n            if (layer != null && layer.GetAdorners(this) != null)\n                layer.Update(this);\n\n            return arrangeSize;\n        }","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs#L1199-L1235","documentation":"InvalidOperationException from DocumentGrid.ArrangeOverride: a visual child being arranged is not a UIElement, meaning the internal visual tree was tampered with. Arrangement requires UIElement children to apply offsets, so the guard throws.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:1217 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not insert arbitrary Visuals into the DocumentGrid child collection","Use the public document/paging APIs to alter content"],"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"}