{"record":{"id":"f140d8af0e58844f","repo":"unoplatform/uno","slug":"unable-to-implicitly-initialize-collection-for-c","errorCode":null,"errorMessage":"Unable to implicitly initialize collection for '{contentProperty.Name}'","messagePattern":"Unable to implicitly initialize collection for '(.+?)'","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":2620,"sourceCode":"\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if (GetKnownNewableListOrCollectionInterface(contentProperty.Type as INamedTypeSymbol, out newableTypeName))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tusing (writer.BlockInvariant(\"{0}{1} = new {2} \", setterPrefix, contentProperty.Name, newableTypeName))\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tforeach (var child in implicitContentChild.Objects)\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tBuildChild(writer, implicitContentChild, child);\n\t\t\t\t\t\t\t\t\t\t\t\twriter.AppendLineIndented(\",\");\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\twriter.AppendLineIndented(\",\");\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tthrow new XamlGenerationException($\"Unable to implicitly initialize collection for '{contentProperty.Name}'\", topLevelControl);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if (IsLazyVisualStateManagerProperty(contentProperty) && !HasDescendantsWithXName(implicitContentChild))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\twriter.AppendLineIndented($\"/* Lazy VisualStateManager property {contentProperty}*/\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse // Content is not a collection\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tvar objectUid = GetObjectUid(topLevelControl);\n\t\t\t\t\t\t\t\t\tvar isLocalized = objectUid != null &&\n\t\t\t\t\t\t\t\t\t\tIsLocalizablePropertyType(contentProperty.Type as INamedTypeSymbol) &&\n\t\t\t\t\t\t\t\t\t\tBuildLocalizedResourceValue(null, contentProperty.Name, objectUid) != null;\n\n\t\t\t\t\t\t\t\t\tif (implicitContentChild.Objects.Count > 0 &&\n\t\t\t\t\t\t\t\t\t\t// A localized value is available. Ignore this implicit content as localized resources take precedence over XAML.\n\t\t\t\t\t\t\t\t\t\t!isLocalized)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// At the time of writing, if useBase is true, setterPrefix will be empty.","sourceCodeStart":2602,"sourceCodeEnd":2638,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L2602-L2638","documentation":"Thrown in the collection-initialization branch of BuildProperties when a content property is detected as collection-like but the generator cannot find a matching collection initializer pattern to emit. It is a fallback for the implicit-content case where the content property name is known but the collection initialization logic (the dictionaries/inserter branches above it) did not apply. This is a rarer, more structural error indicating the XAML's content does not match any supported collection shape.","triggerScenarios":"A content property declared as a collection type whose concrete shape is not recognized by the generator's IsDictionary/IsInitializableCollection heuristics; nested objects inside a content property that is a collection but lacks an Add-compatible initializer the generator can emit.","commonSituations":"Using a custom control whose ContentProperty is a custom collection type the generator does not understand; a third-party type with an unusual collection surface; an edge case in how implicit content is authored for a non-standard dictionary.","solutions":["Replace implicit content with explicit property-element syntax, e.g. <MyControl.Items><x:Array .../></MyControl.Items>, to avoid relying on content-property inference.","If the target is a custom collection type, switch to a standard IList/IDictionary-backed property the generator supports.","Report the content property type to the Uno team if it is a standard WinUI type — this may indicate a generator gap.","Verify you are on a recent Uno version; collection-detection heuristics have been expanded over releases."],"exampleFix":"<!-- before (implicit content on a custom collection property) -->\n<MyControl>\n  <Item/><Item/>\n</MyControl>\n\n<!-- after (explicit property element) -->\n<MyControl>\n  <MyControl.Items>\n    <Item/><Item/>\n  </MyControl.Items>\n</MyControl>","handlingStrategy":"validation","validationCode":"// No simple static check; validate structurally:\n// - Prefer explicit property-element syntax for custom collection content properties.\n// - If using a custom control, confirm its ContentProperty collection type is IList/IDictionary.\n// Review in code review: any <MyControl><Item/>...</MyControl> where MyControl is custom.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For custom controls, back ContentProperty with a standard List<T> or Dictionary<K,V>.","When implicit content fails, switch to explicit <Control.PropertyName> syntax to bypass inference.","Keep Uno updated — collection detection improves each release."],"tags":["xaml","content-property","collection","source-generator","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}