dotnet/wpf · error · ArgumentException
SR.Format(SR.UnexpectedParameterType, value.GetType()…
Error message
SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableCellStructure))
What it means
This ArgumentException is thrown by TableCellStructure.AddChild when the child object is not a TableCellStructure-accepted block element. Cells only accept block-level structure children (ParagraphStructure, TableStructure, ListStructure, FigureStructure) per the XPS schema implemented by this container's twin (see index 2664 pattern in the same file).
Solutions
- Add only ParagraphStructure/TableStructure/ListStructure/FigureStructure instances to the cell
- Wrap inline content in a ParagraphStructure before adding
- Check the actual runtime type in the exception message
- Guard with a type check before AddChild
Example fix
// before
cell.AddChild("some text");
// after
var para = new ParagraphStructure();
cell.Blocks.Add(para); Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not (ParagraphStructure or TableStructure or ListStructure or FigureStructure)) throw new ArgumentException("Cell does not accept this child type"); Type guard
bool IsCellBlock(object o) => o is ParagraphStructure || o is TableStructure || o is ListStructure || o is FigureStructure;
Try / catch
try { cellAddChild(value); } catch (ArgumentException ex) { /* inspect ex.Message for the bad type */ } Prevention
- Wrap inline content in ParagraphStructure before adding to cells
- Never add rows/row-groups to a cell
- Prefer the typed Blocks collection
When it happens
Trigger: Calling AddChild on TableCellStructure with an object that fails the accepted-type test — e.g. a Run, a TextBlock, or a TableRowStructure.
Common situations: Putting inline flow content directly into cells; converting FixedDocument flow code to document-structure code without wrapping content.
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/9643ee41ea63f621.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs:381
public TableRowStructure()
{
_elementType = FixedElement.ElementType.TableRow;
}
public void Add(TableCellStructure tableCell)
{
ArgumentNullException.ThrowIfNull(tableCell);
((IAddChild) this).AddChild(tableCell);
}
void IAddChild.AddChild(object value)
{
if (value is TableCellStructure)
{
_elementList.Add((TableCellStructure)value);
return;
}
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableCellStructure)), nameof(value));
}
void IAddChild.AddText(string text) { }
IEnumerator<TableCellStructure> IEnumerable<TableCellStructure>.GetEnumerator()
{
throw new NotSupportedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<TableCellStructure>)this).GetEnumerator();
}
}
/// <summary>
///
/// </summary>View on GitHub (pinned to 81131a70a4)