{"record":{"id":"e7f9352028400afb","repo":"unoplatform/uno","slug":"unable-to-find-the-type-xclassname-namespace","errorCode":null,"errorMessage":"Unable to find the type '{_xClassName?.Namespace}.{_xClassName?.ClassName}'","messagePattern":"Unable to find the type '(.+?)\\.(.+?)'","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":3849,"sourceCode":"\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow new XamlGenerationException(\"Unable to find x:DataType in enclosing DataTemplate for x:Bind event\", bind);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn GetType(dataTypeObject.Value.ToString() ?? \"\");\n\t\t\t\t\t}\n\t\t\t\t\telse if (_xClassName?.Symbol is not null)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn _xClassName.Symbol;\n\t\t\t\t\t}\n\t\t\t\t\telse if (Generation.AutoGeneratedCodeBehindFiles.TryGetValue(_fileDefinition.UniqueID, out var autoGenBaseType))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Use the XAML-derived base type when code-behind is auto-generated\n\t\t\t\t\t\treturn autoGenBaseType;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new XamlGenerationException($\"Unable to find the type '{_xClassName?.Namespace}.{_xClassName?.ClassName}'\", bind);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tvar targetType = GetTargetType(); // The type of the target object onto which the x:Bind path should be resolved\n\t\t\t\tvar targetInstanceWeakRef = template.isInside\n\t\t\t\t\t// Use of __rootInstance is required to get the top-level DataContext, as it may be changed in the current visual tree by the user.\n\t\t\t\t\t? \"(__rootInstance as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference\"\n\t\t\t\t\t: $\"({targetInstance} as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference\";\n\n\t\t\t\tvar method = ResolveXBindMethod(targetType, path, bind);\n\t\t\t\tvar invokeTarget = (method.isStatic, template.isInside) switch\n\t\t\t\t{\n\t\t\t\t\t(true, _) => method.declaringType.GetFullyQualifiedTypeIncludingGlobal(), // If the method is static, the target onto which the method should be invoked is the declaringType itself\n\t\t\t\t\t(_, true) => $\"((target.Target as {XamlConstants.Types.FrameworkElement})?.DataContext as {targetType.GetFullyQualifiedTypeIncludingGlobal()})?\",\n\t\t\t\t\t_ => $\"(target.Target as {targetType.GetFullyQualifiedTypeIncludingGlobal()})?\"\n\t\t\t\t};\n\n\t\t\t\tvar handler = RegisterChildSubclass(","sourceCodeStart":3831,"sourceCodeEnd":3867,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L3831-L3867","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: x:Class=\"MyApp.MyPage\" but code-behind is\nnamespace WrongApp { public partial class MyPage } \n\n// after: match namespaces\n// XAML:  x:Class=\"MyApp.MyPage\"\n// C#:    namespace MyApp { public partial class MyPage }","handlingStrategy":"validation","validationCode":"# Ensure x:Class in each XAML matches an existing, compiling partial class\nGet-ChildItem -Recurse -Filter *.xaml | ForEach-Object {\n  $m = Select-String -Path $_.FullName -Pattern 'x:Class=\"([^\"]+)\"'\n  if ($m) {\n    $fqn = $m.Matches[0].Groups[1].Value\n    $ns = $fqn.Substring(0, [Math]::Max(0,$fqn.LastIndexOf('.')))\n    $cls = $fqn.Substring($fqn.LastIndexOf('.')+1)\n    $cs = [System.IO.Path]::ChangeExtension($_.FullName, '.xaml.cs')\n    if (-not (Test-Path $cs)) { Write-Warning \"$($_.Name): x:Class=$fqn but no $cs found\" }\n    elseif (-not (Select-String -Path $cs -Pattern \"class\\s+$cls\")) { Write-Warning \"$cs: partial class $cls not found\" }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["xaml","x-bind","x-class","type-resolution","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}