HandyOrg/HandyControl · error · ArgumentException
ExceptionStringTable.DefaultTriggerAttributeInvalidTriggerTy…
Error message
ExceptionStringTable.DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage
What it means
The DefaultTriggerAttribute constructor requires its triggerType parameter to be a type deriving from TriggerBase. Passing any other Type throws ArgumentException DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage with the offending type name.
Solutions
- Pass a Type that derives from TriggerBase (e.g. typeof(EventTrigger), typeof(PropertyChangedTrigger)).
- Verify the trigger type's namespace — Microsoft.Xaml.Behaviors TriggerBase, not a same-named custom class.
- Ensure custom triggers inherit from TriggerBase before referencing them in DefaultTriggerAttribute.
- Fix the constructor call if invoking DefaultTriggerAttribute directly via reflection or codegen.
Example fix
// before [DefaultTrigger(typeof(Button), typeof(Button), "Click")] // after [DefaultTrigger(typeof(Button), typeof(EventTrigger), "Click")]
Defensive patterns
Strategy: validation
Validate before calling
if (triggerType == null || !typeof(TriggerBase).IsAssignableFrom(triggerType))
throw new ArgumentException($"{triggerType?.Name} must derive from TriggerBase"); Type guard
static bool IsValidTriggerType(Type t) => t != null && typeof(TriggerBase).IsAssignableFrom(t);
Try / catch
try { var attr = new DefaultTriggerAttribute(targetType, triggerType); }
catch (ArgumentException ex) when (ex.Message.Contains("InvalidTriggerType")) { /* fix trigger type */ } Prevention
- Only pass TriggerBase-derived types to DefaultTriggerAttribute.
- Compile-time: reference the exact trigger class in the attribute.
- Watch for same-named classes in different namespaces.
- Ensure custom triggers inherit TriggerBase.
When it happens
Trigger: Writing [DefaultTrigger(typeof(Button), typeof(SomeNonTriggerType), ...)] or calling new DefaultTriggerAttribute(targetType, triggerType, params) with a triggerType where typeof(TriggerBase).IsAssignableFrom(triggerType) is false.
Common situations: Typo or autocomplete picking an EventTrigger from the wrong namespace; passing the target class itself as the trigger type; copy-pasting an attribute line and forgetting to change the trigger type; using TriggerAction-derived types by mistake.
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
- ExceptionStringTable.EventTriggerBaseInvalidEventExceptionMe…
- ExceptionStringTable.DuplicateItemInCollectionExceptionMessa…
- ExceptionStringTable.CannotHostBehaviorMultipleTimesExceptio…
- ExceptionStringTable.TypeConstraintViolatedExceptionMessage
- ExceptionStringTable.RetargetedTypeConstraintViolatedExcepti…
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/5bfba4a966d76dc9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/System.Windows.Interactivity/DefaultTriggerAttribute.cs:20
using System.Collections;
using System.Globalization;
namespace HandyControl.Interactivity;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true)]
public sealed class DefaultTriggerAttribute : Attribute
{
private readonly object[] _parameters;
public DefaultTriggerAttribute(Type targetType, Type triggerType, object parameter) : this(targetType,
triggerType, new[] { parameter })
{
}
public DefaultTriggerAttribute(Type targetType, Type triggerType, params object[] parameters)
{
if (!typeof(TriggerBase).IsAssignableFrom(triggerType))
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
ExceptionStringTable.DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage,
new object[] { triggerType.Name }));
TargetType = targetType;
TriggerType = triggerType;
_parameters = parameters;
}
public IEnumerable Parameters =>
_parameters;
public Type TargetType { get; }
public Type TriggerType { get; }
public TriggerBase Instantiate()
{
object obj2 = null;
tryView on GitHub (pinned to 2c0875ebd6)