unoplatform/uno · error · ArgumentException
Binding to XamlSetTypeConverterHandler failed
Error message
Binding to XamlSetTypeConverterHandler failed
What it means
LookupSetTypeConverterHandler throws ArgumentException when a type has [XamlSetTypeConverterAttribute(Name)] but type.GetMethod cannot locate the named static handler. Like the markup-extension variant, the attribute declares a callback for type-converter value assignment; a missing/non-static/misnamed method causes binding to fail.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs:749
protected virtual EventHandler<XamlSetMarkupExtensionEventArgs> LookupSetMarkupExtensionHandler ()
{
var a = this.GetCustomAttribute<XamlSetMarkupExtensionAttribute> ();
if (a == null)
return null;
var mi = type.GetMethod (a.XamlSetMarkupExtensionHandler, flags_get_static);
if (mi == null)
throw new ArgumentException ("Binding to XamlSetMarkupExtensionHandler failed");
return (EventHandler<XamlSetMarkupExtensionEventArgs>) Delegate.CreateDelegate (typeof (EventHandler<XamlSetMarkupExtensionEventArgs>), mi);
}
protected virtual EventHandler<XamlSetTypeConverterEventArgs> LookupSetTypeConverterHandler ()
{
var a = this.GetCustomAttribute<XamlSetTypeConverterAttribute> ();
if (a == null)
return null;
var mi = type.GetMethod (a.XamlSetTypeConverterHandler, flags_get_static);
if (mi == null)
throw new ArgumentException ("Binding to XamlSetTypeConverterHandler failed");
return (EventHandler<XamlSetTypeConverterEventArgs>) Delegate.CreateDelegate (typeof (EventHandler<XamlSetTypeConverterEventArgs>), mi);
}
protected virtual bool LookupTrimSurroundingWhitespace ()
{
// Uno specific: We are not adding TrimSurroundingWhitespaceAttribute to LineBreak, so we special-case it here.
if (PreferredXamlNamespace.Equals("http://schemas.microsoft.com/winfx/2006/xaml/presentation", StringComparison.Ordinal) && Name == "LineBreak")
{
return true;
}
return this.GetCustomAttribute<TrimSurroundingWhitespaceAttribute> () != null;
}
protected virtual XamlValueConverter<TypeConverter> LookupTypeConverter ()
{
var t = UnderlyingType;
if (t == null)View on GitHub (pinned to 0418340488)
Solutions
- Confirm the handler method exists with the exact name from the attribute and is declared 'static'.
- Match the signature: static void M(object sender, XamlSetTypeConverterEventArgs e).
- Remove the attribute if the handler was intentionally deleted.
- Use nameof(...) in the attribute to keep the method reference refactor-safe.
Example fix
// before
[XamlSetTypeConverter("Convert")]
public class MyType {
void Convert(object s, XamlSetTypeConverterEventArgs e) {} // instance -> not found
}
// after
[XamlSetTypeConverter(nameof(OnSetTypeConverter))]
public class MyType {
public static void OnSetTypeConverter(object s, XamlSetTypeConverterEventArgs e) {}
} Defensive patterns
Strategy: validation
Validate before calling
var attr = typeof(T).GetCustomAttribute<XamlSetTypeConverterAttribute>();
if (attr != null) {
var mi = typeof(T).GetMethod(attr.XamlSetTypeConverterHandler,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (mi == null) throw new InvalidOperationException(
$"Handler '{attr.XamlSetTypeConverterHandler}' not found/static on {typeof(T)}");
} Prevention
- Use nameof(...) in the attribute to keep the reference refactor-safe.
- Keep the handler static and matching EventHandler<XamlSetTypeConverterEventArgs>.
- Unit-test attribute-to-method binding for all attributed types.
When it happens
Trigger: Decorating a type with [XamlSetTypeConverter("OnSetTypeConverter")] where OnSetTypeConverter is missing, misspelled, or is an instance method rather than static.
Common situations: Renaming the handler without updating the attribute; converting a static handler to instance during refactoring; attribute copied from a sample whose handler name differs; signature mismatch with EventHandler<XamlSetTypeConverterEventArgs>.
Related errors
- Binding to XamlSetMarkupExtensionHandler failed
- The {0} string passed in the colorString argument is not a r
- context
- Value must be non-null string.
- Member '{0}' could not be resolved to a static member
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/8d252a2f13c6ae72.
Report an issue: GitHub.