unoplatform/uno · error · XamlGenerationException

Unable to implicitly initialize collection for '{contentProp

Error message

Unable to implicitly initialize collection for '{contentProperty.Name}'

What it means

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.

Source

Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:2620

											}
										}
									}
									else if (GetKnownNewableListOrCollectionInterface(contentProperty.Type as INamedTypeSymbol, out newableTypeName))
									{
										using (writer.BlockInvariant("{0}{1} = new {2} ", setterPrefix, contentProperty.Name, newableTypeName))
										{
											foreach (var child in implicitContentChild.Objects)
											{
												BuildChild(writer, implicitContentChild, child);
												writer.AppendLineIndented(",");
											}
										}

										writer.AppendLineIndented(",");
									}
									else
									{
										throw new XamlGenerationException($"Unable to implicitly initialize collection for '{contentProperty.Name}'", topLevelControl);
									}
								}
								else if (IsLazyVisualStateManagerProperty(contentProperty) && !HasDescendantsWithXName(implicitContentChild))
								{
									writer.AppendLineIndented($"/* Lazy VisualStateManager property {contentProperty}*/");
								}
								else // Content is not a collection
								{
									var objectUid = GetObjectUid(topLevelControl);
									var isLocalized = objectUid != null &&
										IsLocalizablePropertyType(contentProperty.Type as INamedTypeSymbol) &&
										BuildLocalizedResourceValue(null, contentProperty.Name, objectUid) != null;

									if (implicitContentChild.Objects.Count > 0 &&
										// A localized value is available. Ignore this implicit content as localized resources take precedence over XAML.
										!isLocalized)
									{
										// At the time of writing, if useBase is true, setterPrefix will be empty.

View on GitHub (pinned to 0418340488)

Solutions

  1. Replace implicit content with explicit property-element syntax, e.g. <MyControl.Items><x:Array .../></MyControl.Items>, to avoid relying on content-property inference.
  2. If the target is a custom collection type, switch to a standard IList/IDictionary-backed property the generator supports.
  3. Report the content property type to the Uno team if it is a standard WinUI type — this may indicate a generator gap.
  4. Verify you are on a recent Uno version; collection-detection heuristics have been expanded over releases.

Example fix

<!-- before (implicit content on a custom collection property) -->
<MyControl>
  <Item/><Item/>
</MyControl>

<!-- after (explicit property element) -->
<MyControl>
  <MyControl.Items>
    <Item/><Item/>
  </MyControl.Items>
</MyControl>
Defensive patterns

Strategy: validation

Validate before calling

// No simple static check; validate structurally:
// - Prefer explicit property-element syntax for custom collection content properties.
// - If using a custom control, confirm its ContentProperty collection type is IList/IDictionary.
// Review in code review: any <MyControl><Item/>...</MyControl> where MyControl is custom.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/f140d8af0e58844f. Report an issue: GitHub.