{"record":{"id":"8d252a2f13c6ae72","repo":"unoplatform/uno","slug":"binding-to-xamlsettypeconverterhandler-failed","errorCode":null,"errorMessage":"Binding to XamlSetTypeConverterHandler failed","messagePattern":"Binding to XamlSetTypeConverterHandler failed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs","lineNumber":749,"sourceCode":"\t\tprotected virtual EventHandler<XamlSetMarkupExtensionEventArgs> LookupSetMarkupExtensionHandler ()\n\t\t{\n\t\t\tvar a = this.GetCustomAttribute<XamlSetMarkupExtensionAttribute> ();\n\t\t\tif (a == null)\n\t\t\t\treturn null;\n\t\t\tvar mi = type.GetMethod (a.XamlSetMarkupExtensionHandler, flags_get_static);\n\t\t\tif (mi == null)\n\t\t\t\tthrow new ArgumentException (\"Binding to XamlSetMarkupExtensionHandler failed\");\n\t\t\treturn (EventHandler<XamlSetMarkupExtensionEventArgs>) Delegate.CreateDelegate (typeof (EventHandler<XamlSetMarkupExtensionEventArgs>), mi);\n\t\t}\n\n\t\tprotected virtual EventHandler<XamlSetTypeConverterEventArgs> LookupSetTypeConverterHandler ()\n\t\t{\n\t\t\tvar a = this.GetCustomAttribute<XamlSetTypeConverterAttribute> ();\n\t\t\tif (a == null)\n\t\t\t\treturn null;\n\t\t\tvar mi = type.GetMethod (a.XamlSetTypeConverterHandler, flags_get_static);\n\t\t\tif (mi == null)\n\t\t\t\tthrow new ArgumentException (\"Binding to XamlSetTypeConverterHandler failed\");\n\t\t\treturn (EventHandler<XamlSetTypeConverterEventArgs>) Delegate.CreateDelegate (typeof (EventHandler<XamlSetTypeConverterEventArgs>), mi);\n\t\t}\n\n\t\tprotected virtual bool LookupTrimSurroundingWhitespace ()\n\t\t{\n\t\t\t// Uno specific: We are not adding TrimSurroundingWhitespaceAttribute to LineBreak, so we special-case it here.\n\t\t\tif (PreferredXamlNamespace.Equals(\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\", StringComparison.Ordinal) && Name == \"LineBreak\")\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn this.GetCustomAttribute<TrimSurroundingWhitespaceAttribute> () != null;\n\t\t}\n\n\t\tprotected virtual XamlValueConverter<TypeConverter> LookupTypeConverter ()\n\t\t{\n\t\t\tvar t = UnderlyingType;\n\t\t\tif (t == null)","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs#L731-L767","documentation":"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.","triggerScenarios":"Decorating a type with [XamlSetTypeConverter(\"OnSetTypeConverter\")] where OnSetTypeConverter is missing, misspelled, or is an instance method rather than static.","commonSituations":"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>.","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."],"exampleFix":"// before\n[XamlSetTypeConverter(\"Convert\")]\npublic class MyType {\n    void Convert(object s, XamlSetTypeConverterEventArgs e) {} // instance -> not found\n}\n\n// after\n[XamlSetTypeConverter(nameof(OnSetTypeConverter))]\npublic class MyType {\n    public static void OnSetTypeConverter(object s, XamlSetTypeConverterEventArgs e) {}\n}","handlingStrategy":"validation","validationCode":"var attr = typeof(T).GetCustomAttribute<XamlSetTypeConverterAttribute>();\nif (attr != null) {\n    var mi = typeof(T).GetMethod(attr.XamlSetTypeConverterHandler,\n        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);\n    if (mi == null) throw new InvalidOperationException(\n        $\"Handler '{attr.XamlSetTypeConverterHandler}' not found/static on {typeof(T)}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["xaml","type-converter","reflection","attribute-binding"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}