dotnet/wpf · error · ArgumentException

SR.Format(SR.DocumentStructureUnexpectedParameterType4…

Error message

SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(), typeof(ParagraphStructure), typeof(TableStructure), typeof(ListStructure), typeof(FigureStructure))

What it means

This ArgumentException is thrown by FixedPageStructure.AddChild (via IAddChild) when a child object added is not one of the four accepted block structure types: ParagraphStructure, TableStructure, ListStructure, or FigureStructure. WPF document structure containers only accept specific strongly-typed children so the XPS document structure remains valid.

Solutions

  1. Pass only ParagraphStructure, TableStructure, ListStructure or FigureStructure instances to AddChild
  2. Wrap content in the correct container (e.g. put rows in TableStructure > TableRowGroupStructure > TableRowStructure)
  3. Check that the element resolved in XAML is the intended structure type, not a same-named different class
  4. Catch ArgumentException around AddChild to surface a clearer message

Example fix

// before
fixedPageStructure.AddChild(new TableRowStructure());
// after
var table = new TableStructure();
table.RowGroups.Add(new TableRowGroupStructure { rows = new TableRowStructure() });
fixedPageStructure.AddChild(table);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value is ParagraphStructure || value is TableStructure || value is ListStructure || value is FigureStructure)) throw new ArgumentException($"{value.GetType()} is not an accepted block structure type");

Type guard

bool IsBlockStructure(object o) => o is ParagraphStructure || o is TableStructure || o is ListStructure || o is FigureStructure;

Try / catch

try { addChild(value); } catch (ArgumentException ex) { /* log ex.Message with value.GetType() */ }

Prevention

When it happens

Trigger: Calling IAddChild.AddChild on a FixedPageStructure (or via XAML parsing) with any object other than ParagraphStructure/TableStructure/ListStructure/FigureStructure, e.g. adding a TableRowStructure or a plain UIElement directly.

Common situations: Hand-building XPS document structure trees in code; XAML that nests a wrong element inside FixedPageStructure; porting code that assumed arbitrary children were accepted.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/8a0fd1a8487d6870. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs:243

        {
            _elementType = FixedElement.ElementType.ListItem;
        }

        public void Add(BlockElement element)
        {
            ArgumentNullException.ThrowIfNull(element);
            ((IAddChild) this).AddChild(element);
        }

        void IAddChild.AddChild(object value)
        {
            if (value is ParagraphStructure || value is TableStructure || value is ListStructure || value is FigureStructure)
            {
                _elementList.Add((BlockElement)value);
                return;
            }

            throw new ArgumentException(SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(),
                typeof(ParagraphStructure), typeof(TableStructure), typeof(ListStructure), typeof(FigureStructure)), nameof(value));
        }
        void IAddChild.AddText(string text) { }

        IEnumerator<BlockElement> IEnumerable<BlockElement>.GetEnumerator()
        {
            throw new NotSupportedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<BlockElement>)this).GetEnumerator();
        }
        
        /// <summary>
        ///
        /// </summary>
        public String Marker

View on GitHub (pinned to 81131a70a4)