{"record":{"id":"a42b87d3b8f81195","repo":"unoplatform/uno","slug":"referenced-type-0-in-event-1-has-no-underlying","errorCode":null,"errorMessage":"Referenced type {0} in event {1} has no underlying type","messagePattern":"Referenced type (.+?) in event (.+?) has no underlying type","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":381,"sourceCode":"\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;\n\t\t\tev.AddEventHandler (obj, Delegate.CreateDelegate (ev.EventHandlerType, target, mi));\n\t\t}\n\n\t\tvoid SetValue (XamlMember member, object value)\n\t\t{\n\t\t\tif (member == XamlLanguage.FactoryMethod)\n\t\t\t\tobject_states.Peek ().FactoryMethod = (string) value;","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L363-L399","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the handler owner is a concrete CLR type (non-null UnderlyingType).","Check that the assembly containing the type is loaded by the schema context / not trimmed away.","Avoid using abstract or XAML-language types as handler owners."],"exampleFix":"// before: handler owner is a schema-only type\n<Button Click=\"x:Null.Handler\" />\n// after: use a real CLR type\n<Button Click=\"local:MyType.ClickHandler\" />","handlingStrategy":"validation","validationCode":"var ownerType = schemaContext.GetXamlType(ownerNamespace, ownerName);\nif (ownerType == null || ownerType.UnderlyingType == null)\n    throw new InvalidOperationException($\"Handler owner '{ownerName}' has no underlying CLR type.\");","typeGuard":null,"tryCatchPattern":"try { /* write event */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"no underlying type\")) {\n    // the resolved owner type has no CLR backing; load/keep the assembly or pick a concrete type.\n}","preventionTips":["Use concrete CLR types as handler owners, not schema-only or XAML-language types.","Ensure the owning assembly is loaded and not trimmed/AOT-stripped.","Validate UnderlyingType is non-null before wiring events."],"tags":["xaml","event","type-resolution","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}