{"record":{"id":"786b8aa8dc575f73","repo":"unoplatform/uno","slug":"cannot-resolve-runtime-type-from-xml-namespace-0","errorCode":null,"errorMessage":"Cannot resolve runtime type from XML namespace '{0}', local name '{1}' with {2} type arguments ({3})","messagePattern":"Cannot resolve runtime type from XML namespace '(.+?)', local name '(.+?)' with (.+?) type arguments \\((.+?)\\)","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs","lineNumber":431,"sourceCode":"\t\t\tif (typeArguments != null && typeArguments.Count > 0) {\n\t\t\t\tgenArgs = (from t in typeArguments select t.UnderlyingType).ToArray ();\n\t\t\t\tif (genArgs.Any (t => t == null))\n\t\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// convert xml namespace to clr namespace and assembly\n\t\t\tstring [] split = ns.Split (_semicolonArray);\n\t\t\tif (split.Length != 2 || split [0].Length < clr_ns_len || split [1].Length <= clr_ass_len)\n\t\t\t\tthrow new XamlParseException (string.Format (CultureInfo.InvariantCulture, \"Cannot resolve runtime namespace from XML namespace '{0}'\", ns));\n\t\t\tstring tns = split [0].Substring (clr_ns_len);\n\t\t\tstring aname = split [1].Substring (clr_ass_len);\n\n\t\t\tstring taqn = GetTypeName (tns, name, genArgs);\n\t\t\tvar ass = OnAssemblyResolve (aname);\n\t\t\t// MarkupExtension type could omit \"Extension\" part in XML name.\n\t\t\tType ret = ass == null ? null : ass.GetType (taqn) ?? ass.GetType (GetTypeName (tns, name + \"Extension\", genArgs));\n\t\t\tif (ret == null)\n\t\t\t\tthrow new XamlParseException (string.Format (CultureInfo.InvariantCulture, \"Cannot resolve runtime type from XML namespace '{0}', local name '{1}' with {2} type arguments ({3})\", ns, name, typeArguments !=null ? typeArguments.Count : 0, taqn));\n\t\t\treturn genArgs == null ? ret : ret.MakeGenericType (genArgs);\n\t\t}\n\t\t\n\t\tstatic string GetTypeName (string tns, string name, Type [] genArgs)\n\t\t{\n\t\t\tstring tfn = tns.Length > 0 ? tns + '.' + name : name;\n\t\t\tif (genArgs != null)\n\t\t\t\ttfn += \"`\" + genArgs.Length;\n\t\t\treturn tfn;\n\t\t}\n\t}\n}\n","sourceCodeStart":413,"sourceCodeEnd":444,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs#L413-L444","documentation":"Thrown by XamlSchemaContext.GetXamlType when an XML namespace (e.g. 'clr-namespace:Foo.Bar;Assembly=MyAsm') was parsed into a CLR namespace and assembly name, but Type.GetType on the resolved assembly returned null for both the plain name and the 'Extension' suffix fallback. It means the XAML referenced a type whose XML namespace mapping is syntactically valid but whose CLR type does not exist (wrong assembly, renamed/removed type, typo in namespace). The four format args are the original XML namespace, the local name, the generic-arity count, and the fully-qualified assembly-qualified name that was attempted.","triggerScenarios":"A XAML file uses xmlns:local='clr-namespace:MyApp.Controls;Assembly=MyApp' and references <local:MissingControl /> where MissingControl no longer exists or was renamed. Also triggered when the Assembly= token names an assembly that OnAssemblyResolve cannot load, or when the clr-namespace value has a typo. Generic types are reported with the computed backtick name (e.g. Foo`1).","commonSituations":"Refactoring that renames or moves a class without updating XAML xmlns mappings; referencing a control from a NuGet package whose assembly name changed between versions; XAML produced by a designer/tool that emits a stale namespace; copy-paste of XAML between projects without fixing the clr-namespace; namespace mismatches after enabling XamlPrecompiled in source generators.","solutions":["Open the XAML file named in the exception and verify the xmlns:clr-namespace value exactly matches the CLR namespace of the target type (case-sensitive).","Verify the Assembly= token matches the assembly that actually contains the type (check the project's AssemblyName and that the type's file is compiled into it).","If the type was renamed, update the XAML element local name, or restore the type; for MarkupExtensions remember the code also tries the 'Extension' suffix automatically so you do not need to add it.","For generic types, confirm the generic arity in XAML (x:TypeArguments) matches the number of type parameters on the CLR type.","If OnAssemblyResolve is custom, ensure the resolver can locate the assembly at the path/version referenced."],"exampleFix":"// before (XAML)\nxmlns:ctrl=\"clr-namespace:MyApp.Legacy.Controls;Assembly=MyApp\"\n<ctrl:OldName />\n\n// after\nxmlns:ctrl=\"clr-namespace:MyApp.Controls;Assembly=MyApp\"\n<ctrl:RenamedControl />","handlingStrategy":"validation","validationCode":"var t = Type.GetType($\"{clrNamespace}.{localName}, {assemblyName}\");\nif (t == null) {\n    // also try MarkupExtension suffix\n    t = Type.GetType($\"{clrNamespace}.{localName}Extension, {assemblyName}\");\n}\nif (t == null) report($\"Type {localName} not found in {clrNamespace}/{assemblyName}\");","typeGuard":null,"tryCatchPattern":"try { var xt = schemaContext.GetXamlType(xamlNamespace, localName); }\ncatch (XamlParseException ex) when (ex.Message.StartsWith(\"Cannot resolve runtime type\")) {\n    // log ns/name, fall back to known-good type or surface a build error\n}","preventionTips":["Keep xmlns clr-namespace mappings under source control alongside the types they reference and update them in the same commit as renames.","Run a XAML schema-validation pass (XamlReader / XamlSchemaContext.GetXamlType) over input at load time to fail fast on bad namespaces.","Wire XAML compile-time checks (source generators) so unresolved types break the build instead of failing at runtime."],"tags":["xaml","type-resolution","clr-namespace","source-generators"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}