dotnet/wpf · error · ArgumentException

SR.Format(SR.UnexpectedParameterType, value.GetType()…

Error message

SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableRowStructure))

What it means

This ArgumentException is thrown by TableRowStructure.AddChild when the child passed is not a TableRowStructure. A row structure only accepts cell structures as children per the XPS document structure schema.

Solutions

  1. Wrap the content in a TableCellStructure and add that instead
  2. Follow the hierarchy: TableRowStructure only contains TableCellStructure; put ParagraphStructure etc. inside cells
  3. Verify the element type in the exception message
  4. Type-check with 'value is TableCellStructure' before calling

Example fix

// before
row.AddChild(new ParagraphStructure());
// after
var cell = new TableCellStructure();
cell.Blocks.Add(new ParagraphStructure());
row.AddChild(cell);
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is not TableRowStructure) throw new ArgumentException("TableRowStructure.AddChild only accepts TableRowStructure");

Type guard

bool IsRow(object o) => o is TableRowStructure;

Try / catch

try { rowAddChild(value); } catch (ArgumentException ex) { /* handle wrong-child-type */ }

Prevention

When it happens

Trigger: Calling AddChild on TableRowStructure with anything other than TableCellStructure, e.g. adding a Run, ParagraphStructure, or raw text element.

Common situations: Mistakenly adding UI or flow content directly into a row when building XPS documents in code or XAML.

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/3154f592882b2faa. Report an issue: GitHub.

Appendix: source

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

        public TableRowGroupStructure()
        {
            _elementType = FixedElement.ElementType.TableRowGroup;
        }

        public void Add(TableRowStructure tableRow)
        {
            ArgumentNullException.ThrowIfNull(tableRow);
            ((IAddChild) this).AddChild(tableRow);
        }
        
        void IAddChild.AddChild(object value)
        {
            if (value is TableRowStructure)
            {
                _elementList.Add((TableRowStructure)value);
                return;
            }
            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableRowStructure)), nameof(value));
        }

        void IAddChild.AddText(string text) { }

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

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<TableRowStructure>)this).GetEnumerator();
        }
    }

    /// <summary>
    ///

View on GitHub (pinned to 81131a70a4)