unoplatform/uno · error · XamlParseException
Cannot resolve runtime namespace from XML namespace '{0}'
Error message
Cannot resolve runtime namespace from XML namespace '{0}' What it means
A XamlParseException thrown by ResolveXamlTypeName when a clr-namespace style XML namespace is malformed. The URI must split into exactly two semicolon-delimited parts — 'clr-namespace:My.Ns' and 'assembly=MyAsm' — and both parts must be long enough. Any other shape (missing assembly segment, extra semicolons, empty parts) triggers this.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs:422
xt = XamlLanguage.AllTypes.FirstOrDefault (t => t.Name == xmlLocalName);
if (xt == null)
throw new FormatException (string.Format (CultureInfo.InvariantCulture, "There is no type '{0}' in XAML namespace", name));
return xt.UnderlyingType;
}
else if (!ns.StartsWith ("clr-namespace:", StringComparison.Ordinal))
return null;
Type [] genArgs = null;
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
- Use the full form: `clr-namespace:MyNamespace;assembly=MyAssembly`.
- Verify the assembly name matches the compiled output assembly exactly (including case).
- Avoid extra semicolons; the URI must contain exactly one ';' separating the two segments.
Example fix
<!-- before --> xmlns:local="clr-namespace:MyApp.Controls" <!-- after --> xmlns:local="clr-namespace:MyApp.Controls;assembly=MyApp"
Defensive patterns
Strategy: validation
Validate before calling
// Validate the clr-namespace URI shape before passing it to the schema context.
const string prefix = "clr-namespace:";
if (ns != null && ns.StartsWith(prefix, StringComparison.Ordinal)) {
var parts = ns.Split(';');
if (parts.Length != 2 || parts[0].Length < prefix.Length || !parts[1].StartsWith("assembly="))
throw new FormatException($"Malformed clr-namespace URI: '{ns}'. Expected 'clr-namespace:N.S;assembly=Asm'.");
} Try / catch
try { /* load/write XAML with clr-namespace mappings */ }
catch (XamlParseException ex) when (ex.Message.Contains("Cannot resolve runtime namespace")) {
// fix the clr-namespace URI to include ';assembly=Name'.
} Prevention
- Always use the full form 'clr-namespace:N.S;assembly=Asm'.
- Verify the assembly name matches the compiled output exactly.
- Ensure exactly one ';' separates the two segments — extra semicolons break parsing.
When it happens
Trigger: Writing `xmlns:local="clr-namespace:My.Ns"` without the `;assembly=...` segment, or `xmlns:local="clr-namespace:;assembly="`, or including an extra semicolon.
Common situations: Hand-authored clr-namespace URIs missing the assembly portion (common when porting from WPF where same-assembly refs sometimes omit it); assembly renamed so the URI is hand-edited incorrectly; copy-paste truncation.
Related errors
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/3c372eed6171d1d2.
Report an issue: GitHub.