{"record":{"id":"225070fa13a304ad","repo":"dotnet/maui","slug":"xc0123","errorCode":"XC0123","errorMessage":"Source property is not a string literal.","messagePattern":"Source property is not a string literal\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs","lineNumber":36,"sourceCode":"\t\t\t\t((ElementNode)node).Properties.TryGetValue(new XmlName(XamlParser.MauiUri, \"Source\"), out sourceNode);\n\n\t\t\tINode styleNode = null;\n\t\t\tif (!((ElementNode)node).Properties.TryGetValue(new XmlName(\"\", \"Style\"), out styleNode) &&\n\t\t\t\t!((ElementNode)node).Properties.TryGetValue(new XmlName(XamlParser.MauiUri, \"Style\"), out styleNode) &&\n\t\t\t\t((ElementNode)node).CollectionItems.Count == 1)\n\t\t\t\tstyleNode = ((ElementNode)node).CollectionItems[0];\n\n\t\t\tif (sourceNode != null && styleNode != null)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.StyleSheetSourceOrContent, node, null);\n\n\t\t\tif (sourceNode == null && styleNode == null)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.StyleSheetNoSourceOrContent, node, null);\n\n\t\t\tif (styleNode != null && styleNode is not ValueNode)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.StyleSheetStyleNotALiteral, node, null);\n\n\t\t\tif (sourceNode != null && sourceNode is not ValueNode)\n\t\t\t\tthrow new BuildException(BuildExceptionCode.StyleSheetSourceNotALiteral, node, null);\n\n\t\t\tif (styleNode != null)\n\t\t\t{\n\t\t\t\tvar style = (styleNode as ValueNode).Value as string;\n\t\t\t\tyield return Create(Ldstr, style);\n\t\t\t\tyield return Create(Call, module.ImportMethodReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls.StyleSheets\", \"StyleSheet\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   methodName: \"FromString\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   parameterTypes: [(\"mscorlib\", \"System\", \"String\")],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   isStatic: true));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvar source = (sourceNode as ValueNode)?.Value as string;\n\t\t\t\tINode rootNode = node;\n\t\t\t\twhile (rootNode is not ILRootNode)\n\t\t\t\t\trootNode = rootNode.Parent;\n\n\t\t\t\tvar rootTargetPath = RDSourceTypeConverter.GetPathForType(context, module, ((ILRootNode)rootNode).TypeReference);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs#L18-L54","documentation":"Thrown when a Source attribute is present on <StyleSheet> but its value is not a string literal ValueNode. The provider emits a resource lookup from a literal path string, so a non-literal (element/binding) value cannot be compiled.","triggerScenarios":"Binding the Source path: <StyleSheet Source=\"{Binding CssPath}\" />; using a nested element as the Source value; OnPlatform/OnIdiom wrapping the path.","commonSituations":"Wanting to choose the stylesheet file at runtime; copy-paste that replaced the literal with a markup expression; IDE refactoring that bound the attribute.","solutions":["Use a plain literal string for Source, e.g. Source=\"Resources/Styles/app.css\".","If runtime selection is required, load the StyleSheet in code-behind instead of via Source.","For per-platform files, conditionally include different <StyleSheet Source=\"...\" /> elements or resolve in code."],"exampleFix":"// before\n<StyleSheet Source=\"{Binding CssPath}\" />\n// after\n<StyleSheet Source=\"Resources/Styles/app.css\" />","handlingStrategy":"validation","validationCode":"// Lint: StyleSheet Source must be a literal, not a binding\nstatic bool StyleSheetSourceIsLiteral(XElement el) {\n    var src = el.Attribute(\"Source\")?.Value;\n    return src == null || (!src.StartsWith(\"{\") && !src.Contains(\"{\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep Source a plain relative resource path string.","Resolve dynamic stylesheet selection in code-behind."],"tags":["xaml","xamlc","stylesheet","css","resource-path","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}