{"record":{"id":"a3e3d03b259d5386","repo":"dotnet/maui","slug":"xc0102","errorCode":"XC0102","errorMessage":"x:DataType expects a string literal, an {{x:Type}} markup or {{x:Null}}.","messagePattern":"x:DataType expects a string literal, an (.+?)\\} markup or (.+?)\\}\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs","lineNumber":576,"sourceCode":"\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif (xDataTypeIsInOuterScope)\n\t\t\t\t{\n\t\t\t\t\tcontext.LoggingHelper.LogWarningOrError(BindingWithXDataTypeFromOuterScope, context.XamlFilePath, node.LineNumber, node.LinePosition, 0, 0, null);\n\t\t\t\t\t// continue compilation\n\t\t\t\t}\n\n\t\t\t\tif (   dataTypeNode is ElementNode enode\n\t\t\t\t\t&& enode.XmlType.NamespaceUri == XamlParser.X2009Uri\n\t\t\t\t\t&& enode.XmlType.Name == nameof(Xaml.NullExtension))\n\t\t\t\t{\n\t\t\t\t\tcontext.LoggingHelper.LogWarningOrError(BindingWithNullDataType, context.XamlFilePath, node.LineNumber, node.LinePosition, 0, 0, null);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif ((dataTypeNode as ValueNode)?.Value is not string dataType)\n\t\t\t\t\tthrow new BuildException(XDataTypeSyntax, dataTypeNode as IXmlLineInfo, null);\n\n\t\t\t\tXmlType dtXType = null;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tdtXType = TypeArgumentsParser.ParseSingle(dataType, node.NamespaceResolver, dataTypeNode as IXmlLineInfo)\n\t\t\t\t\t\t?? throw new BuildException(XDataTypeSyntax, dataTypeNode as IXmlLineInfo, null);\n\t\t\t\t}\n\t\t\t\tcatch (XamlParseException)\n\t\t\t\t{\n\t\t\t\t\tvar prefix = dataType.Contains(\":\") ? dataType.Substring(0, dataType.IndexOf(\":\", StringComparison.Ordinal)) : \"\";\n\t\t\t\t\tthrow new BuildException(XmlnsUndeclared, dataTypeNode as IXmlLineInfo, null, prefix);\n\t\t\t\t}\n\n\t\t\t\ttSourceRef = dtXType.GetTypeReference(context.Cache, module, (IXmlLineInfo)node);\n\t\t\t\tif (tSourceRef == null)\n\t\t\t\t\treturn false;\n\t\t\t}\n","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs#L558-L594","documentation":"Thrown by the compiled-binding logic when the x:DataType node's value is not a string literal. x:DataType must be a plain type-name string, an {x:Type ...} markup, or {x:Null}; an element/markup node that is none of these is rejected before parsing.","triggerScenarios":"x:DataType is set to a non-literal such as a StaticResource/DynamicResource binding or a nested element: `x:DataType=\"{StaticResource T}\"`.","commonSituations":"Developer tries to data-bind the DataType itself, or pastes a markup extension where a literal type name is required.","solutions":["Set x:DataType to a string literal type name, e.g. `x:DataType=\"vm:MainViewModel\"`.","Use {x:Null} if you intentionally want a null data type (note: this emits a warning instead).","Use the {x:Type ...} markup form if you need a Type reference."],"exampleFix":"<!-- before -->\n<ContentPage x:DataType=\"{StaticResource VmType}\">\n\n<!-- after -->\n<ContentPage xmlns:vm=\"clr-namespace:App.ViewModels\"\n             x:DataType=\"vm:MainViewModel\">","handlingStrategy":"validation","validationCode":"// x:DataType must be a literal type string, {x:Type}, or {x:Null}\nstatic bool IsValidXDataType(string raw)\n    => !string.IsNullOrWhiteSpace(raw)\n       && (raw == \"{x:Null}\" || raw.StartsWith(\"{x:Type\") || !raw.StartsWith(\"{\"));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set x:DataType to a literal type name with a declared xmlns prefix.","Never put StaticResource/DynamicResource/binding into x:DataType.","Use {x:Null} only when you intentionally accept a null data type."],"tags":["xaml","xamlc","compiled-bindings","x-datatype"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}