dotnet/wpf · error · NotSupportedException
SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoC…
Error message
SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent
What it means
FlowDocumentReader's template marks a Decorator as its content host; OnApplyTemplate requires that this Decorator has no child of its own. If the template author placed content inside the ContentHost Decorator, NotSupportedException (SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent) is thrown because the reader needs to install its own content there.
Solutions
- Remove any children from the ContentHost Decorator in the template
- Place additional visuals outside the ContentHost Decorator (e.g. in an outer Grid)
- Start from the default FlowDocumentReader template and keep the content host empty
Example fix
// before <Decorator Name="PART_ContentHost"> <Border Background="LightGray"/> </Decorator> // after <Grid> <Decorator Name="PART_ContentHost"/> </Grid>
Defensive patterns
Strategy: validation
Validate before calling
var host = template.FindName("PART_ContentHost", reader) as Decorator;
bool ok = host == null || host.Child == null; Try / catch
try { reader.ApplyTemplate(); }
catch (NotSupportedException) { /* ContentHost decorator has content */ } Prevention
- Keep the content-host Decorator childless in templates
- Put extra visuals in outer containers, not inside the host
- Re-test custom FlowDocumentReader templates after edits
When it happens
Trigger: Custom ControlTemplate for FlowDocumentReader where the Decorator named as ContentHost (PART_ContentHost) contains child elements; copying the default template and adding decorations inside the content host.
Common situations: Restyling FlowDocumentReader to add borders/overlays directly inside the content-host Decorator.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- SR.DocumentViewerStyleMustIncludeContentHost
- SR.TextBoxScrollViewerMarkedAsTextBoxContentMustHaveNoConten…
- SR.TextBoxDecoratorMarkedAsTextBoxContentMustHaveNoContent
- SR.TextBoxInvalidTextContainer
- By default, ToolTip property does not support ToolTip…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7606d3bb62cd8030.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs:98
/// Build Visual tree
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
// Initialize ContentHost.
// If old ContentHost is enabled, disable it first to ensure appropriate cleanup.
if (CurrentViewer != null)
{
DetachViewer(CurrentViewer);
_contentHost.Child = null;
}
_contentHost = GetTemplateChild(_contentHostTemplateName) as Decorator;
if (_contentHost != null)
{
if (_contentHost.Child != null)
{
throw new NotSupportedException(SR.FlowDocumentReaderDecoratorMarkedAsContentHostMustHaveNoContent);
}
SwitchViewingModeCore(ViewingMode);
}
// Initialize FindTooBar host.
// If old FindToolBar is enabled, disable it first to ensure appropriate cleanup.
if (FindToolBar != null)
{
ToggleFindToolBar(false);
}
_findToolBarHost = GetTemplateChild(_findToolBarHostTemplateName) as Decorator;
_findButton = GetTemplateChild(_findButtonTemplateName) as ToggleButton;
}
/// <summary>
/// Whether the master page can be moved to the specified page.
/// </summary>View on GitHub (pinned to 81131a70a4)