unoplatform/uno · error · XamlGenerationException
Unable to find the type '{_xClassName?.Namespace}.{_xClassNa
Error message
Unable to find the type '{_xClassName?.Namespace}.{_xClassName?.ClassName}' What it means
Thrown in the x:Bind event GetTargetType() fallback (the final else) when the binding is NOT inside a template, _xClassName.Symbol is null, and no AutoGeneratedCodeBehindFiles entry exists for this file. The generator needs the page's type symbol to resolve the handler but cannot find it — meaning the x:Class type itself is unresolvable in the compilation. This couples an x:Bind outside a template to a valid, resolvable x:Class type.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:3849
}
throw new XamlGenerationException("Unable to find x:DataType in enclosing DataTemplate for x:Bind event", bind);
}
return GetType(dataTypeObject.Value.ToString() ?? "");
}
else if (_xClassName?.Symbol is not null)
{
return _xClassName.Symbol;
}
else if (Generation.AutoGeneratedCodeBehindFiles.TryGetValue(_fileDefinition.UniqueID, out var autoGenBaseType))
{
// Use the XAML-derived base type when code-behind is auto-generated
return autoGenBaseType;
}
else
{
throw new XamlGenerationException($"Unable to find the type '{_xClassName?.Namespace}.{_xClassName?.ClassName}'", bind);
}
}
var targetType = GetTargetType(); // The type of the target object onto which the x:Bind path should be resolved
var targetInstanceWeakRef = template.isInside
// Use of __rootInstance is required to get the top-level DataContext, as it may be changed in the current visual tree by the user.
? "(__rootInstance as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference"
: $"({targetInstance} as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference";
var method = ResolveXBindMethod(targetType, path, bind);
var invokeTarget = (method.isStatic, template.isInside) switch
{
(true, _) => method.declaringType.GetFullyQualifiedTypeIncludingGlobal(), // If the method is static, the target onto which the method should be invoked is the declaringType itself
(_, true) => $"((target.Target as {XamlConstants.Types.FrameworkElement})?.DataContext as {targetType.GetFullyQualifiedTypeIncludingGlobal()})?",
_ => $"(target.Target as {targetType.GetFullyQualifiedTypeIncludingGlobal()})?"
};
var handler = RegisterChildSubclass(View on GitHub (pinned to 0418340488)
Solutions
- Ensure the code-behind partial class exists and its namespace+class exactly match x:Class in the XAML.
- Confirm the code-behind file is included in the project (not excluded) and compiles.
- If using auto-generated code-behind, verify the file is set up for it; otherwise add the missing partial class.
- Rebuild after fixing namespace mismatches so Roslyn can resolve the type symbol.
Example fix
// before: x:Class="MyApp.MyPage" but code-behind is
namespace WrongApp { public partial class MyPage }
// after: match namespaces
// XAML: x:Class="MyApp.MyPage"
// C#: namespace MyApp { public partial class MyPage } Defensive patterns
Strategy: validation
Validate before calling
# Ensure x:Class in each XAML matches an existing, compiling partial class
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
$m = Select-String -Path $_.FullName -Pattern 'x:Class="([^"]+)"'
if ($m) {
$fqn = $m.Matches[0].Groups[1].Value
$ns = $fqn.Substring(0, [Math]::Max(0,$fqn.LastIndexOf('.')))
$cls = $fqn.Substring($fqn.LastIndexOf('.')+1)
$cs = [System.IO.Path]::ChangeExtension($_.FullName, '.xaml.cs')
if (-not (Test-Path $cs)) { Write-Warning "$($_.Name): x:Class=$fqn but no $cs found" }
elseif (-not (Select-String -Path $cs -Pattern "class\s+$cls")) { Write-Warning "$cs: partial class $cls not found" }
}
} Prevention
- Keep x:Class namespace+class identical to the code-behind partial class.
- Ensure the .xaml.cs file is included in the project and compiles (watch CS0246/CS0115).
- Rebuild after namespace refactors so Roslyn re-resolves the type symbol before x:Bind generation.
When it happens
Trigger: An {x:Bind} event on a page/control whose x:Class type does not compile or is not found by Roslyn (namespace/class mismatch, type in an excluded file, code-behind missing the partial class); using x:Bind in a file without proper code-behind generation.
Common situations: x:Class namespace does not match the code-behind namespace; the code-behind partial class was deleted or misnamed; the project uses auto-generated code-behind but the file is misconfigured; a file newly added without its .xaml.cs companion.
Related errors
- Unable to find class name for toplevel control
- Unable to find x:Class on the top level element
- The type '{objectDefinition.Type}' could not be found
- Unable to find type '{objectDefinition.Type}'
- x:Bind event path cannot be empty
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/e7f9352028400afb.
Report an issue: GitHub.