unoplatform/uno · error · XamlObjectWriterException
Referenced type {0} in event {1} was not found
Error message
Referenced type {0} in event {1} was not found What it means
Thrown in SetEvent while resolving the owner type of a handler value. The handler string (e.g. 'MyType.MyHandler') is split on the last '.'; the left portion is resolved as a XamlType via the name resolver. If resolution returns null the referenced type cannot be located, and the event cannot be wired.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs:379
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;
ev.AddEventHandler (obj, Delegate.CreateDelegate (ev.EventHandlerType, target, mi));
}
void SetValue (XamlMember member, object value)
{View on GitHub (pinned to 0418340488)
Solutions
- Verify the type portion of the handler value is resolvable (correct xmlns prefix and assembly reference).
- Add the missing xmlns prefix mapping for the handler's namespace.
- For local handlers with no '.', the root state type is used — ensure the root type is correct.
Example fix
<!-- before --> <Button Click="wrongns:MyType.ClickHandler" /> <!-- after --> <Button Click="local:MyType.ClickHandler" xmlns:local="clr-namespace:MyApp" />
Defensive patterns
Strategy: validation
Validate before calling
// Verify the handler owner type is resolvable before writing the event.
var ownerType = schemaContext.GetXamlType(ownerNamespace, ownerName);
if (ownerType == null)
throw new InvalidOperationException($"Cannot resolve handler owner type '{ownerName}'."); Try / catch
try { /* write event with handler value */ }
catch (XamlObjectWriterException ex) when (ex.Message.Contains("in event") && ex.Message.Contains("was not found")) {
// fix the type prefix / xmlns for the handler owner.
} Prevention
- Use a correct xmlns prefix for the handler's owning namespace.
- Ensure the owning assembly is referenced by the schema context.
- Validate type names after renames.
When it happens
Trigger: An event handler value like 'Foo.ClickHandler' where 'Foo' cannot be resolved in the current type/name context — wrong xmlns prefix, type not in referenced assemblies, or a typo.
Common situations: Namespace prefix omitted or wrong; assembly containing the handler type not referenced; type renamed; using a fully-qualified name where a prefix is expected.
Related errors
- Referenced type {0} in event {1} has no underlying type
- Event {0} has no underlying member to attach event
- Referenced value method {0} in type {1} indicated by event {
- Type '{0}' is not resolved as a valid type by the type resol
- type
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/ced2e2dc4d899b04.
Report an issue: GitHub.