dotnet/wpf · error
SR.DocumentGridVisualTreeContainsNonUIElement
Error message
SR.DocumentGridVisualTreeContainsNonUIElement
What it means
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.
Solutions
- Do not insert arbitrary Visuals into the DocumentGrid child collection
- Use the public document/paging APIs to alter content
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:1217 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a0a44b82865a9bfd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:1217
//Arrange the page if necessary
UIElement uiPage = _childrenCollection[visualChild] as UIElement;
if (uiPage != null)
{
Point pageOffset;
//Move the page to the right place based on the FlowDirection of the content.
if (_pageCache.IsContentRightToLeft)
{
pageOffset = new Point(Math.Max(ViewportWidth, ExtentWidth) - (xOffset + pageSize.Width), yOffset);
}
else
{
pageOffset = new Point(xOffset, yOffset);
}
uiPage.Arrange(new Rect(pageOffset, pageSize));
}
else
{
throw new InvalidOperationException(SR.DocumentGridVisualTreeContainsNonUIElement);
}
//Increment our horizontal offset to point to where the next page should go.
xOffset += (pageSize.Width + HorizontalPageSpacing);
//Move to the next page.
visualChild++;
}
}
// As we scroll we need to keep the AdornerLayer up-to-date.
// This ensures that annotation components scroll with the content.
AdornerLayer layer = AdornerLayer.GetAdornerLayer(this);
if (layer != null && layer.GetAdorners(this) != null)
layer.Update(this);
return arrangeSize;
}View on GitHub (pinned to 81131a70a4)