{"record":{"id":"74aa4ddeb4e4f07a","repo":"dotnet/maui","slug":"xc0040-74aa4d","errorCode":"XC0040","errorMessage":"Cannot convert value \"{0}\" to \"{1}\".","messagePattern":"Cannot convert value \"(.+?)\" to \"(.+?)\"\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledConverters/TypeTypeConverter.cs","lineNumber":44,"sourceCode":"\t\t\tif (split.Length == 2)\n\t\t\t\txmlType = new XmlType(node.NamespaceResolver.LookupNamespace(split[0]), split[1], null);\n\t\t\telse\n\t\t\t\txmlType = new XmlType(node.NamespaceResolver.LookupNamespace(\"\"), split[0], null);\n\n\t\t\tvar typeRef = xmlType.GetTypeReference(context.Cache, module, (IXmlLineInfo)node);\n\t\t\tif (typeRef == null)\n\t\t\t\tgoto error;\n\n\t\t\tyield return Create(Ldtoken, module.ImportReference(typeRef));\n\t\t\tyield return Create(Call, module.ImportMethodReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   methodName: \"GetTypeFromHandle\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   parameterTypes: new[] { (\"mscorlib\", \"System\", \"RuntimeTypeHandle\") },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   isStatic: true));\n\n\t\t\tyield break;\n\n\t\terror:\n\t\t\tthrow new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Type));\n\t\t}\n\t}\n}","sourceCodeStart":26,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledConverters/TypeTypeConverter.cs#L26-L47","documentation":"XC0040 Conversion thrown by TypeTypeConverter when a XAML string representing a System.Type reference cannot be resolved. The converter splits on ':' to extract an optional XML namespace prefix and type name, resolves the namespace, then calls GetTypeReference. Failure occurs if the value is empty, contains more than one colon, the namespace prefix is undeclared, or the named type cannot be found in the resolved assembly.","triggerScenarios":"Setting an x:Type or Type-typed property (e.g. DataTemplate content, TargetType in a Style) to a type name with an undeclared namespace prefix, a non-existent type, or a malformed reference like 'local:MyType:Extra'. A missing or wrong xmlns declaration causes namespace lookup to fail.","commonSituations":"Forgetting to declare the xmlns:local (or other prefix) at the root element. Using a type name that does not exist or was renamed. Typo in the type name. The type is in an assembly that is not referenced.","solutions":["Ensure the XML namespace prefix used in the type reference is declared at the root element (e.g. xmlns:local='clr-namespace:MyApp.Models').","Verify the type name is spelled correctly and exists in the referenced namespace/assembly.","Ensure the value contains at most one ':' separating the prefix from the type name.","Confirm the assembly containing the type is referenced by the project."],"exampleFix":"<!-- before (missing xmlns:vm declaration) -->\n<ContentPage>\n  <DataTemplate x:DataType=\"vm:ItemViewModel\" />\n</ContentPage>\n\n<!-- after -->\n<ContentPage xmlns:vm=\"clr-namespace:MyApp.ViewModels\">\n  <DataTemplate x:DataType=\"vm:ItemViewModel\" />\n</ContentPage>","handlingStrategy":"validation","validationCode":"// Validate a Type XAML reference: non-empty, at most one prefix colon, namespace resolvable\nstatic bool IsValidTypeReference(string value, Func<string, string> lookupNamespace)\n{\n    if (string.IsNullOrEmpty(value)) return false;\n    var split = value.Split(':');\n    if (split.Length > 2) return false;\n    var prefix = split.Length == 2 ? split[0] : \"\";\n    return lookupNamespace(prefix) != null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare xmlns prefixes at the root element before using them in type references.","Ensure the type exists in the referenced assembly and namespace.","Use at most one ':' to separate the prefix from the type name."],"tags":["xaml","maui","xamlc","type-converter","type-resolution","xmlns","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}