unoplatform/uno · error · XamlGenerationException
Unable to find type '{objectDefinition.Type}'
Error message
Unable to find type '{objectDefinition.Type}' What it means
Thrown when processing an x:Name member (line 3490 branch): the generator needs the object's type symbol to register a backing field (RegisterBackingField), but FindType(objectDefinition.Type) returns null. This differs from 309 — here the object passed earlier checks but specifically the Name-backing-field registration requires a resolvable type and it is missing.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:3497
{
ValidateName(value, member);
writer.AppendLineIndented($@"__nameScope.RegisterName(""{value}"", {writer.AppliedParameterName});");
}
if (
member.Member.Name == "Name"
&& !IsAttachedProperty(member)
&& !isMemberInsideResourceDictionary.isInside
)
{
nameMember = member;
var type = FindType(objectDefinition.Type)?.GetFullyQualifiedTypeIncludingGlobal();
if (type == null)
{
throw new XamlGenerationException($"Unable to find type '{objectDefinition.Type}'", objectDefinition);
}
writer.AppendLineInvariantIndented("__that.{0} = {1};", value, writer.AppliedParameterName);
// value is validated as non-null in ValidateName call above.
RegisterBackingField(type, value!, FindObjectFieldAccessibility(objectDefinition));
}
else if (member.Member.Name == "Name"
&& member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace)
{
writer.AppendLineInvariantIndented("// x:Name {0}", member.Value, member.Value);
}
else if (member.Member.Name == "Key")
{
writer.AppendLineInvariantIndented("// Key {0}", member.Value, member.Value);
}
else if (member.Member.Name == "DeferLoadStrategy"
&& member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace)
{View on GitHub (pinned to 0418340488)
Solutions
- Resolve the type exactly as for error 309: fix the xmlns prefix, add the project/PackageReference, correct any typo.
- Confirm the element's type compiles on the current UnoTargetFrameworkOverride (TFM).
- Remove the x:Name if the element type is intentionally unresolved/optional, or gate the XAML by platform.
Example fix
<!-- before --> <Page xmlns:w="using:Missing.Lib"> <w:BadControl x:Name="MyControl"/> </Page> <!-- after --> <Page xmlns:w="using:Real.Lib"> <w:RealControl x:Name="MyControl"/> </Page>
Defensive patterns
Strategy: validation
Validate before calling
# Same as 309: ensure every type used in XAML resolves. Additionally, list x:Name'd elements
# and confirm their types compile:
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
Select-String -Path $_.FullName -Pattern '<(\w+:)?([\w.]+)\b[^>]*x:Name' |
ForEach-Object { Write-Host "Named element of type: $($_.Matches[0].Groups[2].Value)" }
# Then build and resolve any CS0246 alongside the XAML error. Prevention
- Resolve type-resolution issues (see 309) before adding x:Name.
- Confirm the type exists on the target TFM when cross-targeting.
When it happens
Trigger: An element with x:Name whose type cannot be resolved by the compilation (undeclared xmlns, missing assembly reference, typo); an element inside a ResourceDictionary that also has x:Name but whose type is unknown.
Common situations: Naming a control whose type comes from an unreferenced assembly; renaming/moving a control type without updating xmlns; platform-conditional types referenced on a TFM where they don't exist.
Related errors
- The type '{objectDefinition.Type}' could not be found
- The value '{value}' is an invalid value for 'Name' property
- The name '{value}' is already defined in this scope
- Unable to find the type '{_xClassName?.Namespace}.{_xClassNa
- Type '{0}' is not resolved as a valid type by the type resol
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/9a7d3fa19ca9d5fe.
Report an issue: GitHub.