dotnet/wpf · error · ArgumentException
SR.Format(SR.UnexpectedParameterType, value.GetType()…
Error message
SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(ListItemStructure))
What it means
This AddChild implementation (ListItemStructure container) accepts only ListItemStructure children (nested list items) and throws ArgumentException with UnexpectedParameterType for any other value, echoing the value's type and the expected ListItemStructure type.
Solutions
- Wrap NamedElement in the intermediate structure level before adding, or add it to the ListStructure level that accepts it.
- Only add ListItemStructure instances for nested list items here.
- Use the typed Add(ListItemStructure) method for compile-time checking.
Example fix
// before
listItemStructure.AddChild(new NamedElement("x:P"));
// after
var nested = new ListItemStructure();
listStructure.AddChild(nested);
// named elements belong via the structure level that accepts them Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not ListItemStructure) throw new ArgumentException($"Expected ListItemStructure, got {value.GetType()}."); Type guard
bool IsListItemStructure(object v) => v is ListItemStructure;
Try / catch
try { listItem.AddChild(value); } catch (ArgumentException) { /* place NamedElements at the correct structural level instead */ } Prevention
- Only nest ListItemStructure inside ListItemStructure for sub-lists.
- NamedElements belong under paragraph-level containers, not directly under items.
- Use the typed Add(ListItemStructure) method to catch errors at compile time.
When it happens
Trigger: Calling AddChild with a NamedElement or ParagraphStructure etc. on a ListItemStructure; nesting error while constructing ListStructure/ListItemStructure trees where a named element was placed at item level instead of paragraph level.
Common situations: XAML fixed-document structures with a <NamedElement> directly under <ListItemStructure> instead of under a child container; programmatic tree building that skipped one hierarchy level.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- SR.Format(SR.DocumentStructureUnexpectedParameterType1…
- SR.Format(SR.DocumentStructureUnexpectedParameterType4…
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
- ' ' is not a valid value for ' '.
- ArgumentException(message, name)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4799f82b03316260.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs:201
{
_elementType = FixedElement.ElementType.List;
}
public void Add(ListItemStructure listItem)
{
ArgumentNullException.ThrowIfNull(listItem);
((IAddChild) this).AddChild(listItem);
}
void IAddChild.AddChild(object value)
{
if (value is ListItemStructure)
{
_elementList.Add((ListItemStructure)value);
return;
}
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(ListItemStructure)), nameof(value));
}
void IAddChild.AddText(string text) { }
IEnumerator<ListItemStructure> IEnumerable<ListItemStructure>.GetEnumerator()
{
throw new NotSupportedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<ListItemStructure>)this).GetEnumerator();
}
}
/// <summary>
///
/// </summary>
public class ListItemStructure : SemanticBasicElement, IAddChild, IEnumerable<BlockElement>, IEnumerableView on GitHub (pinned to 81131a70a4)