unoplatform/uno · error · XamlObjectWriterException

Referenced type {0} in event {1} has no underlying type

Error message

Referenced type {0} in event {1} has no underlying type

What it means

Thrown in SetEvent after the handler's owner XamlType is resolved but found to have UnderlyingType == null. A XamlType may exist in the schema (e.g. a XAML language type or abstract schema type) yet have no backing CLR type; without a CLR type the writer cannot reflect for the handler method.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:381

				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;
			ev.AddEventHandler (obj, Delegate.CreateDelegate (ev.EventHandlerType, target, mi));
		}

		void SetValue (XamlMember member, object value)
		{
			if (member == XamlLanguage.FactoryMethod)
				object_states.Peek ().FactoryMethod = (string) value;

View on GitHub (pinned to 0418340488)

Solutions

  1. Ensure the handler owner is a concrete CLR type (non-null UnderlyingType).
  2. Check that the assembly containing the type is loaded by the schema context / not trimmed away.
  3. Avoid using abstract or XAML-language types as handler owners.

Example fix

// before: handler owner is a schema-only type
<Button Click="x:Null.Handler" />
// after: use a real CLR type
<Button Click="local:MyType.ClickHandler" />
Defensive patterns

Strategy: validation

Validate before calling

var ownerType = schemaContext.GetXamlType(ownerNamespace, ownerName);
if (ownerType == null || ownerType.UnderlyingType == null)
    throw new InvalidOperationException($"Handler owner '{ownerName}' has no underlying CLR type.");

Try / catch

try { /* write event */ }
catch (XamlObjectWriterException ex) when (ex.Message.Contains("no underlying type")) {
    // the resolved owner type has no CLR backing; load/keep the assembly or pick a concrete type.
}

Prevention

When it happens

Trigger: Referencing, as an event handler owner, a type that exists only as a XAML-schema concept with no CLR backing — e.g. a XAML-language intrinsic or a type from an assembly the schema context could not load.

Common situations: Schema context configured with reference assemblies that lack the real type; referencing a XAML-language type as a handler owner; trimming/AOT scenarios stripping the underlying type.

Related errors


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