{"record":{"id":"c222f2b1110ae392","repo":"dotnet/maui","slug":"xc0002","errorCode":"XC0002","errorMessage":"EventHandler \"{0}\" with correct signature not found in type \"{1}\".","messagePattern":"EventHandler \"(.+?)\" with correct signature not found in type \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs","lineNumber":1485,"sourceCode":"\t\t\t\t//check if the handler signature matches the Invoke signature;\n\t\t\t\tvar invoke = module.ImportReference(eventinfo.EventType.ResolveCached(context.Cache).GetMethods().First(eventmd => eventmd.Name == \"Invoke\"));\n\t\t\t\tinvoke = invoke.ResolveGenericParameters(eventinfo.EventType, module);\n\t\t\t\tif (!md.methodDef.ReturnType.InheritsFromOrImplements(context.Cache, invoke.ReturnType) || invoke.Parameters.Count != md.methodDef.Parameters.Count)\n\t\t\t\t\treturn false;\n\n\t\t\t\tif (!invoke.ContainsGenericParameter)\n\t\t\t\t\tfor (var i = 0; i < invoke.Parameters.Count; i++)\n\t\t\t\t\t\tif (!invoke.Parameters[i].ParameterType.InheritsFromOrImplements(context.Cache, md.methodDef.Parameters[i].ParameterType))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t//TODO check generic parameters if any\n\n\t\t\t\treturn true;\n\t\t\t});\n\t\t\tMethodReference handlerRef = null;\n\t\t\tif (methodDef != null)\n\t\t\t\thandlerRef = methodDef.ResolveGenericParameters(declTypeRef, module);\n\t\t\tif (methodDef == null)\n\t\t\t\tthrow new BuildException(MissingEventHandler, iXmlLineInfo, null, value, declaringType);\n\n\t\t\t//FIXME: eventually get the right ctor instead fo the First() one, just in case another one could exists (not even sure it's possible).\n\t\t\tvar ctor = module.ImportReference(eventinfo.EventType.ResolveCached(context.Cache).GetConstructors().First());\n\t\t\tctor = ctor.ResolveGenericParameters(eventinfo.EventType, module);\n\n\t\t\tif (methodDef.IsStatic)\n\t\t\t{\n\t\t\t\tyield return Create(Ldnull);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (context.Root is VariableDefinition)\n\t\t\t\t\tforeach (var instruction in (context.Root as VariableDefinition).LoadAs(context.Cache, ctor.Parameters[0].ParameterType.ResolveGenericParameters(ctor), module))\n\t\t\t\t\t\tyield return instruction;\n\t\t\t\telse if (context.Root is FieldDefinition)\n\t\t\t\t{\n\t\t\t\t\tyield return Create(Ldarg_0);\n\t\t\t\t\tyield return Create(Ldfld, context.Root as FieldDefinition);","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs#L1467-L1503","documentation":"Thrown when wiring an event in XAML (e.g. `Clicked=\"Handler\"`) and the compiler finds no method on the declaring type whose name matches and whose signature matches the event delegate's Invoke (return type and parameter types). The AllMethods search returns no match, so MissingEventHandler is thrown.","triggerScenarios":"An event handler referenced in XAML is missing, renamed, has the wrong parameter list, is inaccessible, or its signature does not match the event's delegate (e.g. custom EventArgs).","commonSituations":"Typo in the handler name; handler deleted during refactor; method is private to a different type; using `(object, EventArgs)` for an event that expects a specific EventArgs subclass (still matches), or a non-matching custom delegate.","solutions":["Add a method with the matching name and signature, typically `void Handler(object sender, EventArgs e)` (or the event's specific EventArgs type).","Ensure the method is accessible from the XAML's code-behind type (the declaring type).","Correct any typo in the handler name referenced in XAML."],"exampleFix":"<!-- before -->\n<Button Clicked=\"OnClikc\" />\n\n<!-- after -->\n<Button Clicked=\"OnClick\" />\n\n// code-behind\nvoid OnClick(object sender, EventArgs e) { /* ... */ }","handlingStrategy":"validation","validationCode":"// Verify a handler matching an event delegate exists on the code-behind type\nstatic bool HandlerExists(Type owner, Type delegateType, string handlerName)\n    => owner.GetMethods().Any(m => m.Name == handlerName && DelegateCompatible(m, delegateType));\n\nstatic bool DelegateCompatible(System.Reflection.MethodInfo m, Type delegateType)\n{\n    var invoke = delegateType.GetMethod(\"Invoke\");\n    return m.ReturnType == invoke.ReturnType\n        && m.GetParameters().Select(p => p.ParameterType)\n            .SequenceEqual(invoke.GetParameters().Select(p => p.ParameterType));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name handlers exactly as referenced in XAML.","Use the standard (object sender, EventArgs e) signature (or the event's specific EventArgs).","Keep handlers accessible from the XAML code-behind type."],"tags":["xaml","xamlc","event-handler","code-behind"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}