{"record":{"id":"3f819902f1bd90c0","repo":"dotnet/maui","slug":"xc0122","errorCode":"XC0122","errorMessage":"Style property or Content is not a string literal.","messagePattern":"Style property or Content is not a string literal\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs","lineNumber":33,"sourceCode":"\t\t{\n\t\t\t((ElementNode)node).Properties.TryGetValue(new XmlName(\"\", \"Source\"), out INode sourceNode);\n\t\t\tif (sourceNode == null)\n\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)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs#L15-L51","documentation":"Thrown when inline Style content is present but is not a string literal ValueNode (e.g. it is an element node or nested markup). The compiled provider can only emit a Ldstr + StyleSheet.FromString call, so the content must be a plain string of CSS.","triggerScenarios":"Putting a child element inside <StyleSheet> instead of raw CSS text; binding the Style content; embedding a node like <StyleSheet><OnPlatform/></StyleSheet>.","commonSituations":"Trying to make the CSS platform-conditional via OnPlatform inside the style block; authoring structured nodes where a literal was expected; tooling that wraps text in an element.","solutions":["Replace nested elements with raw CSS text inside <StyleSheet>.","For platform-specific CSS, use separate <StyleSheet> elements per platform or handle selection in code-behind.","If the CSS is large, move it to a .css resource file and use Source instead."],"exampleFix":"// before\n<StyleSheet>\n  <OnPlatform x:TypeArguments=\"x:String\" ... />\n</StyleSheet>\n// after\n<StyleSheet>\n  label { color: red; }\n</StyleSheet>","handlingStrategy":"validation","validationCode":"// Lint: inline StyleSheet content must be plain text\nstatic bool StyleSheetContentIsLiteral(XElement el) =>\n    el.Attribute(\"Source\") == null && !el.Elements().Any() && !string.IsNullOrWhiteSpace(el.Value);\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Put only raw CSS text inside <StyleSheet>; never child elements.","For platform-varying CSS, use separate stylesheet files or code-behind."],"tags":["xaml","xamlc","stylesheet","css","markup-extension","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}