{"record":{"id":"ced2e2dc4d899b04","repo":"unoplatform/uno","slug":"referenced-type-0-in-event-1-was-not-found","errorCode":null,"errorMessage":"Referenced type {0} in event {1} was not found","messagePattern":"Referenced type (.+?) in event (.+?) was not found","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":379,"sourceCode":"\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;\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{","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L361-L397","documentation":"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.","triggerScenarios":"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.","commonSituations":"Namespace prefix omitted or wrong; assembly containing the handler type not referenced; type renamed; using a fully-qualified name where a prefix is expected.","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."],"exampleFix":"<!-- before -->\n<Button Click=\"wrongns:MyType.ClickHandler\" />\n<!-- after -->\n<Button Click=\"local:MyType.ClickHandler\" xmlns:local=\"clr-namespace:MyApp\" />","handlingStrategy":"validation","validationCode":"// Verify the handler owner type is resolvable before writing the event.\nvar ownerType = schemaContext.GetXamlType(ownerNamespace, ownerName);\nif (ownerType == null)\n    throw new InvalidOperationException($\"Cannot resolve handler owner type '{ownerName}'.\");","typeGuard":null,"tryCatchPattern":"try { /* write event with handler value */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"in event\") && ex.Message.Contains(\"was not found\")) {\n    // fix the type prefix / xmlns for the handler owner.\n}","preventionTips":["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."],"tags":["xaml","event","type-resolution","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}