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

  1. Confirm the handler method exists with the exact name from the attribute and is declared 'static'.
  2. Match the signature: static void M(object sender, XamlSetTypeConverterEventArgs e).
  3. Remove the attribute if the handler was intentionally deleted.
  4. 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

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


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/8d252a2f13c6ae72. Report an issue: GitHub.