dotnet/wpf · error · InvalidOperationException
SR.Format(SR.VisualTriggerSettersIncludeUnsupportedSetterTyp…
Error message
SR.Format(SR.VisualTriggerSettersIncludeUnsupportedSetterType, setters[i].GetType().Name)
What it means
TriggerBase.ProcessSettersCollection throws InvalidOperationException (VisualTriggerSettersIncludeUnsupportedSetterType, type name) when a visual trigger's Setters collection contains a Setter-derived type other than Setter or DynamicResource-bearing setters it supports (e.g., EventSetter). Visual/property triggers only accept property setters.
Solutions
- Remove EventSetter/unsupported items from the trigger's Setters collection
- Handle events in the control or template code instead of trigger setters
- Only place plain <Setter> (or supported Setter/DynamicResource) entries in Trigger.Setters
Example fix
// before <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> <EventSetter Event="Click" Handler="OnClick"/> </Trigger> // after <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Red"/> </Trigger> <!-- attach event handler on the element or via EventTrigger/Command -->
Defensive patterns
Strategy: type-guard
Validate before calling
if (setter is not Setter) throw new InvalidOperationException($"{setter.GetType().Name} not supported in trigger setters."); Type guard
static bool IsSupportedTriggerSetter(SetterBase s) => s is Setter;
Try / catch
try { trigger.Setters.Add(setter); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Setter")) { /* remove unsupported setter */ } Prevention
- Only use plain <Setter> inside Trigger.Setters
- Attach event handlers outside trigger setter collections
- Don't share SetterBase collections between styles and triggers
When it happens
Trigger: Adding an EventSetter (or other unsupported SetterBase subclass) to a Trigger's Setters collection, in XAML (<EventSetter> inside <Trigger.Setters>) or code.
Common situations: Copy-pasting an <EventSetter> from a Style.Setters block into a Trigger.Setters block; programmatically reusing a setters list across style and trigger scopes.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
- Animation_NoTextChildren
- Animation_NoTextChildren
- ArgumentException: path
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4cf99b4f31823d1a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs:300
}
else
{
target = ProcessParametersVisualTreeChild(dp, target); // name string will get interned
}
DynamicResourceExtension dynamicResource = value as DynamicResourceExtension;
if (dynamicResource == null)
{
AddToPropertyValues(target, dp, value, PropertyValueType.Trigger);
}
else
{
AddToPropertyValues(target, dp, dynamicResource.ResourceKey, PropertyValueType.PropertyTriggerResource);
}
}
else
{
throw new InvalidOperationException(SR.Format(SR.VisualTriggerSettersIncludeUnsupportedSetterType, setters[i].GetType().Name));
}
}
}
}
// Define the DO's inheritance context
internal override DependencyObject InheritanceContext
{
get { return _inheritanceContext; }
}
// Receive a new inheritance context (this will be a FE/FCE)
internal override void AddInheritanceContext(DependencyObject context, DependencyProperty property)
{
InheritanceContextHelper.AddInheritanceContext(context,
this,
ref _hasMultipleInheritanceContexts,View on GitHub (pinned to 81131a70a4)