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
- Add only TableRowGroupStructure instances; nest TableRowStructure inside the row group
- Match the XPS hierarchy: TableStructure contains TableRowGroupStructure contains TableRowStructure contains TableCellStructure
- Inspect value.GetType() in the message to see what was actually passed
- 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
- Remember the hierarchy: group contains rows, rows contain cells
- Build tables top-down: TableStructure -> TableRowGroupStructure -> TableRowStructure -> TableCellStructure
- Use typed collections instead of IAddChild
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
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
- SR.Collection_BadDestArray
- SR.Collection_BadDestArray
- SR.Collection_BadDestArray
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)