unoplatform/uno · error · XamlGenerationException

The type '{objectDefinition.Type}' could not be found

Error message

The type '{objectDefinition.Type}' could not be found

What it means

Thrown in the apply-block builder when an object has traits requiring special initialization (extended properties, phasing, is a FrameworkElement, has IsParsing, or has an x:Uid) AND useGenericApply is false AND FindType cannot resolve the object's type. The generator needs the real type symbol to emit the apply block, so an unresolvable type here is fatal. The objectDefinition.Type string is whatever the XAML declared.

Source

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

		private void BuildExtendedProperties(IIndentedStringBuilder outerwriter, XamlObjectDefinition objectDefinition, bool useGenericApply = false)
		{
			_generatorContext.CancellationToken.ThrowIfCancellationRequested();

			TryAnnotateWithGeneratorSource(outerwriter);
			var objectUid = GetObjectUid(objectDefinition);

			var extendedProperties = GetExtendedProperties(objectDefinition);
			var hasChildrenWithPhase = HasChildrenWithPhase(objectDefinition);
			var objectDefinitionType = FindType(objectDefinition.Type);
			var isFrameworkElement = IsType(objectDefinitionType, Generation.FrameworkElementSymbol.Value);
			var hasIsParsing = HasIsParsing(objectDefinitionType);

			if (extendedProperties.Any() || hasChildrenWithPhase || isFrameworkElement || hasIsParsing || !objectUid.IsNullOrEmpty())
			{
				if (!useGenericApply && objectDefinitionType is null)
				{
					throw new XamlGenerationException($"The type '{objectDefinition.Type}' could not be found", objectDefinition);
				}

				using (var writer = CreateApplyBlock(outerwriter, objectDefinition))
				{
					XamlMemberDefinition? uidMember = null;
					XamlMemberDefinition? nameMember = null;
					ComponentDefinition? componentDefinition = null;
					string? uiAutomationId = null;
					string[]? extractionTargetMembers = null;

					if (_isUiAutomationMappingEnabled)
					{
						// Look up any potential UI automation member mappings available for the current object definition
						extractionTargetMembers = _uiAutomationMappings
							?.FirstOrDefault(m => _metadataHelper.FindTypeByFullName(m.Key) is INamedTypeSymbol mappingKeySymbol && (IsType(objectDefinitionType, mappingKeySymbol) || IsImplementingInterface(objectDefinitionType, mappingKeySymbol)))
							.Value
							?.ToArray() ?? [];
					}

View on GitHub (pinned to 0418340488)

Solutions

  1. Verify the xmlns prefix for the type resolves to the correct namespace URI and that the assembly is referenced by the project.
  2. Fix any typo in the type name in the XAML.
  3. Add the missing project/PackageReference that contains the type.
  4. If the type is platform-specific, gate the XAML or use ApiExtensibility/OperatingSystem.Is* so it exists on the target TFM.

Example fix

<!-- before -->
<Page xmlns:ctrl="using:WrongNamespace">
  <ctrl:MyWidget/>
</Page>

<!-- after -->
<Page xmlns:ctrl="using:MyApp.Controls">
  <ctrl:MyWidget/>
</Page>
Defensive patterns

Strategy: validation

Validate before calling

# Cross-check xmlns prefixes map to referenced assemblies/types
# (best done by building the project — Roslyn reports CS0246 for unresolvable types)
# Pre-check: list xmlns declarations and verify the using-clause namespaces exist
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
  Select-String -Path $_.FullName -Pattern 'xmlns:(\w+)="(?:using:|clr-namespace:)([^"]+)"' |
    ForEach-Object { Write-Host "prefix $($_.Matches[0].Groups[1].Value) -> $($_.Matches[0].Groups[2].Value)" }
}

Prevention

When it happens

Trigger: Referencing a type in XAML whose xmlns prefix is undeclared or maps to an assembly not referenced; a typo in a type name; a custom control whose containing project/assembly is not referenced by the XAML's project.

Common situations: Adding a custom control without a project reference; wrong xmlns:local URI; a control moved/renamed between Uno versions; conditional compilation removing a type from a target where the XAML still references it.

Related errors


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