{"record":{"id":"abe37e53aff204b4","repo":"unoplatform/uno","slug":"item","errorCode":null,"errorMessage":"item","messagePattern":"item","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs","lineNumber":76,"sourceCode":"\t\t{\n\t\t\tif (type == null || type.UnderlyingType == null)\n\t\t\t\tthrow new NotSupportedException (String.Format (CultureInfo.InvariantCulture, \"Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}'\", type));\n\t\t}\n\n\t\tpublic EventHandler<XamlSetMarkupExtensionEventArgs> SetMarkupExtensionHandler {\n\t\t\tget { return type == null ? null : type.SetMarkupExtensionHandler; }\n\t\t}\n\n\t\tpublic EventHandler<XamlSetTypeConverterEventArgs> SetTypeConverterHandler {\n\t\t\tget { return type == null ? null : type.SetTypeConverterHandler; }\n\t\t}\n\n\t\tpublic virtual void AddToCollection (object instance, object item)\n\t\t{\n\t\t\tif (instance == null)\n\t\t\t\tthrow new ArgumentNullException (\"instance\");\n\t\t\tif (item == null)\n\t\t\t\tthrow new ArgumentNullException (\"item\");\n\n\t\t\tvar ct = instance.GetType ();\n\t\t\tvar xct = type == null ? null : type.SchemaContext.GetXamlType (ct);\n\t\t\tMethodInfo mi = null;\n\n\t\t\t// FIXME: this method lookup should be mostly based on GetAddMethod(). At least iface method lookup must be done there.\n\t\t\tif (type != null && type.UnderlyingType != null) {\n\t\t\t\tif (!xct.IsCollection) // not sure why this check is done only when UnderlyingType exists...\n\t\t\t\t\tthrow new NotSupportedException (String.Format (CultureInfo.InvariantCulture, \"Non-collection type '{0}' does not support this operation\", xct));\n\t\t\t\tif (ct.IsAssignableFrom (type.UnderlyingType))\n\t\t\t\t\tmi = GetAddMethod (type.SchemaContext.GetXamlType (item.GetType ()));\n\t\t\t}\n\n\t\t\tif (mi == null) {\n\t\t\t\tif (ct.IsGenericType) {\n\t\t\t\t\tmi = ct.GetMethod (\"Add\", ct.GetGenericArguments ());\n\t\t\t\t\tif (mi == null)\n\t\t\t\t\t\tmi = LookupAddMethod (ct, typeof (ICollection<>).MakeGenericType (ct.GetGenericArguments ()));","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs#L58-L94","documentation":"Thrown by XamlTypeInvoker.AddToCollection when the `item` argument is null. The method reflects an Add(T) overload based on item.GetType(), so a null item both breaks type resolution and is usually a semantic error in XAML (XAML items are objects with identity).","triggerScenarios":"Calling AddToCollection(instance, null) directly, or a XAML writer adding a child that resolved to null (e.g. a null MarkupExtension result, or a property whose value computed to null being added to a collection).","commonSituations":"Markup extensions returning null that get added to a collection; x:Null used in a position where an item is expected to be added; bugs in object construction that yield null items.","solutions":["Do not add null items to XAML collections — filter nulls out before calling AddToCollection.","If x:Null is intentional, handle it at the writer level (skip the add) rather than passing null through.","Ensure MarkupExtensions return a real instance."],"exampleFix":"// before\ntype.Invoker.AddToCollection(collection, item); // item may be null\n\n// after\nif (item != null) {\n    type.Invoker.AddToCollection(collection, item);\n}","handlingStrategy":"validation","validationCode":"// before AddToCollection\nif (item == null) return; // skip null items","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter null items out before adding to collections.","Handle x:Null at the writer level rather than passing it through as an item."],"tags":["xaml","schema","invoker","collection","argument-validation"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}