dotnet/wpf · error · ArgumentException

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

Error message

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

What it means

This ArgumentException is thrown by TableRowGroupStructure.AddChild when the supplied child is not a TableRowGroupStructure. The container only accepts row groups as children, keeping the XPS table structure hierarchy (TableStructure -> TableRowGroupStructure) valid.

Solutions

  1. Add only TableRowGroupStructure instances; nest TableRowStructure inside the row group
  2. Match the XPS hierarchy: TableStructure contains TableRowGroupStructure contains TableRowStructure contains TableCellStructure
  3. Inspect value.GetType() in the message to see what was actually passed
  4. Guard the call with an 'is TableRowGroupStructure' check

Example fix

// before
rowGroup.AddChild(new TableRowStructure());
// after
var row = new TableRowStructure();
rowGroup.Rows.Add(row); // via typed collection, or add rows through a group's own API
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

bool IsRowGroup(object o) => o is TableRowGroupStructure;

Try / catch

try { rowGroupAddChild(value); } catch (ArgumentException ex) { /* surface ex.ParamName and message */ }

Prevention

When it happens

Trigger: Calling AddChild on TableRowGroupStructure with an object that is not TableRowGroupStructure, e.g. adding a TableRowStructure directly or a ParagraphStructure.

Common situations: Building XPS tables programmatically and skipping a hierarchy level; XAML where a row is placed directly in a table without a row group.

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/34632316b9655bfc. Report an issue: GitHub.

Appendix: source

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

        public TableStructure()
        {
            _elementType = FixedElement.ElementType.Table;
        }

        public void Add(TableRowGroupStructure tableRowGroup)
        {
            ArgumentNullException.ThrowIfNull(tableRowGroup);
            ((IAddChild) this).AddChild(tableRowGroup);
        }
        
        void IAddChild.AddChild(object value)
        {
            if (value is TableRowGroupStructure)
            {
                _elementList.Add((TableRowGroupStructure)value);
                return;
            }
            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableRowGroupStructure)), nameof(value));
        }
        
        void IAddChild.AddText(string text) { }
        
        IEnumerator<TableRowGroupStructure> IEnumerable<TableRowGroupStructure>.GetEnumerator()
        {
            throw new NotSupportedException();
        }

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

    /// <summary>
    ///
    /// </summary>

View on GitHub (pinned to 81131a70a4)