dotnet/maui · error · BuildException
XC0000
XC0000
Error message
Cannot resolve type "{0}". What it means
Raised when a type referenced in XAML cannot be resolved to any CLR type after consulting all XmlnsDefinitionAttribute mappings. TryGetTypeReference returns false (no matching type) and GetTypeReference throws BuildException(TypeResolution) with the unresolved 'namespace:name' string.
Source
Thrown at src/Controls/src/Build.Tasks/XmlTypeExtensions.cs:143
if (types.Distinct(TypeRefComparer.Default).Skip(1).Any())
{
typeReference = null;
return false;
}
var type = types.Distinct(TypeRefComparer.Default).FirstOrDefault();
if (type != null && typeArguments != null && type.HasGenericParameters)
type = module.ImportReference(type).MakeGenericInstanceType(typeArguments.Select(x => x.GetTypeReference(cache, module, xmlInfo)).ToArray());
return (typeReference = (type == null) ? null : module.ImportReference(type)) != null;
}
public static TypeReference GetTypeReference(this XmlType xmlType, XamlCache cache, ModuleDefinition module, IXmlLineInfo xmlInfo, bool expandToExtension = true)
{
if (TryGetTypeReference(xmlType, cache, module, xmlInfo, expandToExtension: expandToExtension, out TypeReference typeReference))
return typeReference;
throw new BuildException(BuildExceptionCode.TypeResolution, xmlInfo, null, $"{xmlType.NamespaceUri}:{xmlType.Name}");
}
static XmlnsDefinitionAttribute GetXmlnsDefinition(this CustomAttribute ca, AssemblyDefinition asmDef)
{
var attr = new XmlnsDefinitionAttribute(
ca.ConstructorArguments[0].Value as string,
ca.ConstructorArguments[1].Value as string);
string assemblyName = null;
if (ca.Properties.Count > 0)
assemblyName = ca.Properties[0].Argument.Value as string;
attr.AssemblyName = assemblyName ?? asmDef.Name.FullName;
return attr;
}
public static IList<XmlnsPrefixAttribute> GetXmlnsPrefixAttributes(ModuleDefinition module)
{
var xmlnsPrefixes = new List<XmlnsPrefixAttribute>();View on GitHub (pinned to f377ff1c5e)
Solutions
- Add or fix the xmlns declaration, e.g. xmlns:local='clr-namespace:MyApp.Views;assembly=MyApp'.
- Confirm the assembly containing the type is referenced by the project and that its name/namespace match the clr-namespace string exactly (case-sensitive).
- If using a custom xmlns uri, ensure the providing assembly has the matching XmlnsDefinitionAttribute and is included in the build.
Example fix
<!-- before --> <local:MyView xmlns:local="clr-namespace:WrongNamespace;assembly=MyApp" /> <!-- after --> <local:MyView xmlns:local="clr-namespace:MyApp.Views;assembly=MyApp" />
Defensive patterns
Strategy: validation
Validate before calling
// At design time, confirm the clr-namespace and assembly referenced in xmlns exist. // Example: xmlns:local="clr-namespace:MyApp.Views;assembly=MyApp" // -> assert typeof(MyApp.Views.SomeType).Assembly.GetName().Name == "MyApp".
Prevention
- Keep xmlns clr-namespace strings in sync with the actual namespace and assembly name (case-sensitive).
- Add the assembly/project reference that owns the type to every head project that uses the XAML.
- Use a custom xmlns uri backed by XmlnsDefinitionAttribute for shared libraries.
When it happens
Trigger: TryGetTypeReference finds zero candidate types for the XmlType (types.Distinct(...).FirstOrDefault() is null), so the public GetTypeReference throws BuildException(BuildExceptionCode.TypeResolution, ...) with '{NamespaceUri}:{Name}'.
Common situations: Missing xmlns declaration for a custom control; a clr-namespace that points at the wrong namespace or assembly; the referenced assembly is not referenced by the project or was renamed; case mismatch in namespace or type name.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/b086f7d9cc2aeb48.
Report an issue: GitHub.