dotnet/maui · error · BuildException

XC0000

XC0000

Error message

Cannot resolve type "{0}".

What it means

Thrown by x:Type when the type name string was provided but XmlTypeExtensions.GetTypeReference returned null, meaning no matching type could be located in the referenced assemblies. The compiler emits a GetTypeFromHandle token, so it must have a real TypeReference.

Source

Thrown at src/Controls/src/Build.Tasks/CompiledMarkupExtensions/TypeExtension.cs:33

		{
			memberRef = module.ImportReference(context.Cache, ("mscorlib", "System", "Type"));
			var name = new XmlName("", "TypeName");

			if (!node.Properties.TryGetValue(name, out INode typeNameNode) && node.CollectionItems.Any())
				typeNameNode = node.CollectionItems[0];

			if (!(typeNameNode is ValueNode valueNode))
				throw new BuildException(BuildExceptionCode.PropertyMissing, node as IXmlLineInfo, null, "TypeName", typeof(Microsoft.Maui.Controls.Xaml.TypeExtension));

			if (!node.Properties.ContainsKey(name))
			{
				node.Properties[name] = typeNameNode;
				node.CollectionItems.Clear();
			}

			var typeref = module.ImportReference(XmlTypeExtensions.GetTypeReference(context.Cache, valueNode.Value as string, module, node as BaseNode));

			context.TypeExtensions[node] = typeref ?? throw new BuildException(BuildExceptionCode.TypeResolution, node as IXmlLineInfo, null, valueNode.Value);

			return new List<Instruction> {
				Create(Ldtoken, module.ImportReference(typeref)),
				Create(Call, module.ImportMethodReference(context.Cache, ("mscorlib", "System", "Type"),
														  methodName: "GetTypeFromHandle",
														  parameterTypes: [("mscorlib", "System", "RuntimeTypeHandle")],
														  isStatic: true)),
			};
		}
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Check the xmlns declaration: clr-namespace must match exactly and the assembly name must be correct.
  2. Add the missing ProjectReference or PackageReference that contains the type.
  3. Rebuild after renaming to refresh the cache, and correct the spelling/namespace.
  4. If the type is internal, make it public or grant InternalsVisibleTo.
  5. Confirm the type exists for the current target framework (not a platform-only type used in shared XAML).

Example fix

// before
xmlns:local="clr-namespace:MyApp.Controlz"
<x:Type TypeName="local:MyView" />
// after
xmlns:local="clr-namespace:MyApp.Controls"
<x:Type TypeName="local:MyView" />
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the type the same way the compiler will, before building
static bool TypeIsReferenceable(string xmlNamespace, string typeName, IEnumerable<Assembly> refs) {
    var full = $"{xmlNamespace}:{typeName}";
    return refs.SelectMany(a => a.GetTypes()).Any(t => t.FullName == typeName || t.Name == typeName);
}

Prevention

When it happens

Trigger: Typo in the type or namespace; missing xmlns prefix mapping; the assembly containing the type is not referenced by the project; the type is internal and not visible; using a type from an assembly that is loaded only at runtime.

Common situations: Refactor renamed a class/namespace but XAML was not updated; referenced a type in a project not added as a ProjectReference/PackageReference; xmlns uses the wrong clr-namespace or assembly name; type exists in a platform-specific assembly not included for the active target.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/c425b76e64d76df2. Report an issue: GitHub.