unoplatform/uno · error · XamlObjectWriterException
Event {0} has no underlying member to attach event
Error message
Event {0} has no underlying member to attach event What it means
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.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:374
escaped_objects.Pop ();
} else if (xm == XamlLanguage.Initialization) {
// ... and no need to do anything. The object value to pop *is* the return value.
} else if (xm == XamlLanguage.Name || xm == state.Type.GetAliasedProperty (XamlLanguage.Name)) {
string name = (string) CurrentMemberState.Value;
name_scope.RegisterName (name, state.Value);
} else {
if (xm.IsEvent)
SetEvent (xm, (string) CurrentMemberState.Value);
else if (!xm.IsReadOnly) // exclude read-only object such as collection item.
SetValue (xm, CurrentMemberState.Value);
}
}
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Types manipulated here have been marked earlier")]
void SetEvent (XamlMember member, string value)
{
if (member.UnderlyingMember == null)
throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "Event {0} has no underlying member to attach event", member));
int idx = value.LastIndexOf ('.');
var xt = idx < 0 ? root_state.Type : ResolveTypeFromName (value.Substring (0, idx));
if (xt == null)
throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "Referenced type {0} in event {1} was not found", value, member));
if (xt.UnderlyingType == null)
throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "Referenced type {0} in event {1} has no underlying type", value, member));
string mn = idx < 0 ? value : value.Substring (idx + 1);
var ev = (EventInfo) member.UnderlyingMember;
// get an appropriate MethodInfo overload whose signature matches the event's handler type.
// FIXME: this may need more strict match. RuntimeBinder may be useful here.
var eventMethodParams = ev.EventHandlerType.GetMethod ("Invoke").GetParameters ();
var target = root_state.Value;
var mi = target.GetType().GetMethod (mn, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, (from pi in eventMethodParams select pi.ParameterType).ToArray (), null);
if (mi == null)
throw new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, "Referenced value method {0} in type {1} indicated by event {2} was not found", mn, value, member));
var obj = object_states.Peek ().Value;View on GitHub (pinned to 0418340488)
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.
Example fix
<!-- before: Clickk is not a real event --> <Button Clickk="OnClick" /> <!-- after --> <Button Click="OnClick" />
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the event exists as a real CLR EventInfo on the target type.
var ev = target.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);
if (ev == null)
throw new InvalidOperationException($"Event '{eventName}' not found on {target.GetType()}."); Try / catch
try { /* write event member */ }
catch (XamlObjectWriterException ex) when (ex.Message.Contains("no underlying member")) {
// the event member has no CLR EventInfo; fix the schema/member/event name.
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Referenced value method {0} in type {1} indicated by event {
- Specified static factory method '{0}' for type '{1}' was not
- Referenced type {0} in event {1} was not found
- Referenced type {0} in event {1} has no underlying type
- The {0} string passed in the colorString argument is not a r
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/92cfd0479690ef9b.
Report an issue: GitHub.