unoplatform/uno · error · XamlParseException

Cannot resolve runtime type from XML namespace '{0}', local

Error message

Cannot resolve runtime type from XML namespace '{0}', local name '{1}' with {2} type arguments ({3})

What it means

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.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs:431

			if (typeArguments != null && typeArguments.Count > 0) {
				genArgs = (from t in typeArguments select t.UnderlyingType).ToArray ();
				if (genArgs.Any (t => t == null))
					return null;
			}

			// convert xml namespace to clr namespace and assembly
			string [] split = ns.Split (_semicolonArray);
			if (split.Length != 2 || split [0].Length < clr_ns_len || split [1].Length <= clr_ass_len)
				throw new XamlParseException (string.Format (CultureInfo.InvariantCulture, "Cannot resolve runtime namespace from XML namespace '{0}'", ns));
			string tns = split [0].Substring (clr_ns_len);
			string aname = split [1].Substring (clr_ass_len);

			string taqn = GetTypeName (tns, name, genArgs);
			var ass = OnAssemblyResolve (aname);
			// MarkupExtension type could omit "Extension" part in XML name.
			Type ret = ass == null ? null : ass.GetType (taqn) ?? ass.GetType (GetTypeName (tns, name + "Extension", genArgs));
			if (ret == null)
				throw 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));
			return genArgs == null ? ret : ret.MakeGenericType (genArgs);
		}
		
		static string GetTypeName (string tns, string name, Type [] genArgs)
		{
			string tfn = tns.Length > 0 ? tns + '.' + name : name;
			if (genArgs != null)
				tfn += "`" + genArgs.Length;
			return tfn;
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. 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).
  2. 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).
  3. 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.
  4. For generic types, confirm the generic arity in XAML (x:TypeArguments) matches the number of type parameters on the CLR type.
  5. If OnAssemblyResolve is custom, ensure the resolver can locate the assembly at the path/version referenced.

Example fix

// before (XAML)
xmlns:ctrl="clr-namespace:MyApp.Legacy.Controls;Assembly=MyApp"
<ctrl:OldName />

// after
xmlns:ctrl="clr-namespace:MyApp.Controls;Assembly=MyApp"
<ctrl:RenamedControl />
Defensive patterns

Strategy: validation

Validate before calling

var t = Type.GetType($"{clrNamespace}.{localName}, {assemblyName}");
if (t == null) {
    // also try MarkupExtension suffix
    t = Type.GetType($"{clrNamespace}.{localName}Extension, {assemblyName}");
}
if (t == null) report($"Type {localName} not found in {clrNamespace}/{assemblyName}");

Try / catch

try { var xt = schemaContext.GetXamlType(xamlNamespace, localName); }
catch (XamlParseException ex) when (ex.Message.StartsWith("Cannot resolve runtime type")) {
    // log ns/name, fall back to known-good type or surface a build error
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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