{"record":{"id":"92cfd0479690ef9b","repo":"unoplatform/uno","slug":"event-0-has-no-underlying-member-to-attach-event","errorCode":null,"errorMessage":"Event {0} has no underlying member to attach event","messagePattern":"Event (.+?) has no underlying member to attach event","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":374,"sourceCode":"\t\t\t\tescaped_objects.Pop ();\n\t\t\t} else if (xm == XamlLanguage.Initialization) {\n\t\t\t\t// ... and no need to do anything. The object value to pop *is* the return value.\n\t\t\t} else if (xm == XamlLanguage.Name || xm == state.Type.GetAliasedProperty (XamlLanguage.Name)) {\n\t\t\t\tstring name = (string) CurrentMemberState.Value;\n\t\t\t\tname_scope.RegisterName (name, state.Value);\n\t\t\t} else {\n\t\t\t\tif (xm.IsEvent)\n\t\t\t\t\tSetEvent (xm, (string) CurrentMemberState.Value);\n\t\t\t\telse if (!xm.IsReadOnly) // exclude read-only object such as collection item.\n\t\t\t\t\tSetValue (xm, CurrentMemberState.Value);\n\t\t\t}\n\t\t}\n\n\t\t[UnconditionalSuppressMessage(\"Trimming\", \"IL2075\", Justification = \"Types manipulated here have been marked earlier\")]\n\t\tvoid SetEvent (XamlMember member, string value)\n\t\t{\n\t\t\tif (member.UnderlyingMember == null)\n\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Event {0} has no underlying member to attach event\", member));\n\n\t\t\tint idx = value.LastIndexOf ('.');\n\t\t\tvar xt = idx < 0 ? root_state.Type : ResolveTypeFromName (value.Substring (0, idx));\n\t\t\tif (xt == null)\n\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Referenced type {0} in event {1} was not found\", value, member));\n\t\t\tif (xt.UnderlyingType == null)\n\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Referenced type {0} in event {1} has no underlying type\", value, member));\n\t\t\tstring mn = idx < 0 ? value : value.Substring (idx + 1);\n\t\t\tvar ev = (EventInfo) member.UnderlyingMember;\n\t\t\t// get an appropriate MethodInfo overload whose signature matches the event's handler type.\n\t\t\t// FIXME: this may need more strict match. RuntimeBinder may be useful here.\n\t\t\tvar eventMethodParams = ev.EventHandlerType.GetMethod (\"Invoke\").GetParameters ();\n\t\t\t\n\t\t\tvar target = root_state.Value;\n\t\t\tvar mi = target.GetType().GetMethod (mn, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, (from pi in eventMethodParams select pi.ParameterType).ToArray (), null);\n\t\t\tif (mi == null)\n\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Referenced value method {0} in type {1} indicated by event {2} was not found\", mn, value, member));\n\t\t\tvar obj = object_states.Peek ().Value;","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L356-L392","documentation":"Thrown by SetEvent when handling an event-typed XamlMember whose UnderlyingMember is null. The writer needs a real CLR EventInfo to attach a delegate; a member that represents an event at the XAML level but has no backing CLR event (synthetic, unknown, or misconfigured) cannot be wired and fails here.","triggerScenarios":"A XAML attribute on an event whose XamlMember was created without a CLR EventInfo — e.g. a custom XamlSchemaContext/XamlMember for a nonexistent event, an attachable event not properly registered, or a typo that produced a synthetic event member.","commonSituations":"Custom XamlSchemaContext returning event members without underlying CLR members; attachable events missing their backing; controls where the event was renamed but the XAML/schema still references the old name.","solutions":["Verify the event name spelled in XAML exists as a real CLR event on the target type.","If using a custom XamlSchemaContext/XamlMember, ensure it carries a non-null UnderlyingMember for events.","Register attachable events with their backing add/remove accessors."],"exampleFix":"<!-- before: Clickk is not a real event -->\n<Button Clickk=\"OnClick\" />\n<!-- after -->\n<Button Click=\"OnClick\" />","handlingStrategy":"validation","validationCode":"// Confirm the event exists as a real CLR EventInfo on the target type.\nvar ev = target.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);\nif (ev == null)\n    throw new InvalidOperationException($\"Event '{eventName}' not found on {target.GetType()}.\");","typeGuard":null,"tryCatchPattern":"try { /* write event member */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"no underlying member\")) {\n    // the event member has no CLR EventInfo; fix the schema/member/event name.\n}","preventionTips":["Spell event names exactly as declared on the target type.","When supplying custom XamlMembers, always set the UnderlyingMember for events.","Register attachable events with proper add/remove accessors."],"tags":["xaml","event","reflection","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}