dotnet/wpf · error · ArgumentException
SR.Format(SR.UnexpectedParameterType, o.GetType()…
Error message
SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(Setter))
What it means
TriggerActionCollection (Trigger) validates that items added to a TriggerActionCollection are Setter instances via CheckChildIsSetter. Passing any other object type throws ArgumentException with SR.UnexpectedParameterType naming the actual type and expected Setter type.
Solutions
- Add only Setter instances to this collection; use Trigger.Setters for property setters.
- If you meant an action, use the correct collection (e.g. EventTrigger.Actions for TriggerAction objects).
- Check the object type before adding: if (item is Setter) collection.Add(item);
Example fix
// before trigger.Setters.Add(new TriggerAction()); // throws // after trigger.Setters.Add(new Setter(UIElement.OpacityProperty, 0.5));
Defensive patterns
Strategy: type-guard
Validate before calling
if (item is not Setter) throw new ArgumentException($"Expected Setter, got {item?.GetType().Name}"); Type guard
static bool IsSetter(object o) => o is Setter;
Try / catch
try { collection.Add(item); }
catch (ArgumentException ex) { log.Error($"Wrong collection for {item.GetType().Name}: {ex.Message}"); } Prevention
- Add Setter objects only to Trigger.Setters
- Use EventTrigger.Actions for TriggerAction objects
- Verify collection semantics when refactoring style construction code
When it happens
Trigger: Adding a non-Setter (e.g. a TriggerAction, EventSetter in the wrong collection, or arbitrary object) to an EventTrigger/Trigger action collection, or calling the internal validation path with a wrong-typed item.
Common situations: Programmatic style construction where the wrong collection is used (Setters vs Actions); refactoring that moved setters into action collections.
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.BadFixedTextPosition
- SR.Collection_BadType
- SR.ConditionValueOfExpressionNotSupported
- SR.Format(SR.Animation_AnimationTimelineTypeMismatch…
- SR.Format(SR.Animation_AnimationTimelineTypeMismatch…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/49c12a3cd9b8a54e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs:181
///</param>
void IAddChild.AddText (string text)
{
// Verify Context Access
VerifyAccess();
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
// Shared by PropertyTrigger, MultiPropertyTrigger, DataTrigger, MultiDataTrigger
internal static Setter CheckChildIsSetter( object o )
{
ArgumentNullException.ThrowIfNull(o);
Setter setter = o as Setter;
if (setter == null)
{
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(Setter)), nameof(o));
}
return setter;
}
internal sealed override void Seal()
{
if (IsSealed)
{
return;
}
if (_property != null)
{
// Ensure valid condition
if (!_property.IsValidValue(_value))
{
throw new InvalidOperationException(SR.Format(SR.InvalidPropertyValue, _value, _property.Name ));View on GitHub (pinned to 81131a70a4)