{"record":{"id":"b89625963dcdd8b3","repo":"dotnet/maui","slug":"xc0120","errorCode":"XC0120","errorMessage":"StyleSheet cannot have both a Source and a content.","messagePattern":"StyleSheet cannot have both a Source and a content\\.","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs","lineNumber":27,"sourceCode":"\nnamespace Microsoft.Maui.Controls.XamlC\n{\n\tclass StyleSheetProvider : ICompiledValueProvider\n\t{\n\t\tpublic IEnumerable<Instruction> ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context)\n\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));","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs#L9-L45","documentation":"Thrown by the StyleSheet value provider when a <StyleSheet> element declares both a Source attribute and inline Style content (or a single collection item). A stylesheet must come from exactly one place: an external resource file (Source) or an inline CSS literal (Style/content), not both.","triggerScenarios":"Writing <StyleSheet Source=\"styles.css\"> label { color: red; } </StyleSheet>; declaring both Source=\"...\" and a Style attribute; having one collection item plus a Source.","commonSituations":"Migrating from inline to external CSS and forgetting to remove the inline block; merging two XAML fragments; IDE auto-completing the Source while inline content remains.","solutions":["Remove either the Source attribute or the inline Style/content, keeping exactly one.","If you need both sources, split into two separate <StyleSheet> elements.","After editing, rebuild to confirm only one of sourceNode/styleNode is non-null."],"exampleFix":"// before\n<StyleSheet Source=\"shared.css\">\n  label { color: red; }\n</StyleSheet>\n// after\n<StyleSheet Source=\"shared.css\" />","handlingStrategy":"validation","validationCode":"// Lint: a <StyleSheet> must not have both Source and content\nstatic bool StyleSheetHasOneSource(XElement el) =>\n    !(el.Attribute(\"Source\") != null && (!el.IsEmpty && !string.IsNullOrWhiteSpace(el.Value)));\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide per stylesheet: external Source OR inline content, never both.","When migrating inline->external, delete the inline block in the same commit.","Split multi-source needs into separate <StyleSheet> elements."],"tags":["xaml","xamlc","stylesheet","css","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}