{"record":{"id":"6e262a51bafc42fa","repo":"dotnet/maui","slug":"resource-source-not-found","errorCode":null,"errorMessage":"Resource '{source}' not found.","messagePattern":"Resource '(.+?)' not found\\.","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs","lineNumber":60,"sourceCode":"\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);\n\t\t\t\tvar uri = new Uri(source, UriKind.Relative);\n\n\t\t\t\tvar resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(uri, rootTargetPath);\n\t\t\t\t//fail early\n\t\t\t\tif (XamlCTask.GetResourceIdForPath(context.Cache, module, resourcePath) == null)\n\t\t\t\t\tthrow new XamlParseException($\"Resource '{source}' not found.\", node);\n\n\t\t\t\tyield return Create(Ldstr, resourcePath); //resourcePath\n\n\t\t\t\tyield return Create(Ldtoken, module.ImportReference(((ILRootNode)rootNode).TypeReference));\n\t\t\t\tyield return Create(Call, module.ImportMethodReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"), methodName: \"GetTypeFromHandle\", parameterTypes: new[] { (\"mscorlib\", \"System\", \"RuntimeTypeHandle\") }, isStatic: true));\n\t\t\t\tyield return Create(Callvirt, module.ImportPropertyGetterReference(context.Cache, (\"mscorlib\", \"System\", \"Type\"), propertyName: \"Assembly\", flatten: true)); //assembly\n\n\t\t\t\tforeach (var instruction in node.PushXmlLineInfo(context))\n\t\t\t\t\tyield return instruction; //lineinfo\n\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: \"FromResource\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   parameterTypes: [(\"mscorlib\", \"System\", \"String\"), (\"mscorlib\", \"System.Reflection\", \"Assembly\"), (\"System.Xml.ReaderWriter\", \"System.Xml\", \"IXmlLineInfo\")],\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\n\t\t\t//the variable is of type `object`. fix that\n\t\t\tvar vardef = new VariableDefinition(module.ImportReference(context.Cache, (\"Microsoft.Maui.Controls\", \"Microsoft.Maui.Controls.StyleSheets\", \"StyleSheet\")));","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs#L42-L78","documentation":"Thrown (as a raw XamlParseException, no XC code) when a StyleSheet Source path was given as a literal but XamlCTask.GetResourceIdForPath returned null, meaning no embedded resource at that path is visible to the assembly's ResourceManager. The compiler fails early before emitting a FromResource call.","triggerScenarios":"Source points to a .css file that is not an <EmbeddedResource>; the resource path does not match the project's default namespace + folder structure; the file was excluded from the build; casing mismatch on case-sensitive resource lookups.","commonSituations":"Added the .css as 'None' or 'Content' instead of 'EmbeddedResource'; folder structure changed so the logical resource id differs; file added at the wrong location in the project; build action not propagated in multi-targeted projects.","solutions":["Set the .css file's build action to 'MauiCss' (or 'EmbeddedResource') so it is embedded.","Match the Source path to the actual logical resource id (default namespace + folders, dot-separated).","Confirm the file is included for all target frameworks in the build.","Verify casing exactly matches between Source and the file on disk."],"exampleFix":"// before\n<!-- file at Styles/app.css, build action = None -->\n<StyleSheet Source=\"app.css\" />\n// after\n<!-- set build action = MauiCss -->\n<StyleSheet Source=\"Styles/app.css\" />","handlingStrategy":"validation","validationCode":"// Before building, confirm the embedded resource id exists\nstatic bool CssResourceExists(Assembly asm, string resourcePath) {\n    var ids = asm.GetManifestResourceNames();\n    return ids.Any(n => n.Equals(resourcePath, StringComparison.Ordinal)\n                     || n.EndsWith(\".\" + resourcePath));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set .css build action to 'MauiCss' / 'EmbeddedResource'.","Match Source casing to the file path exactly.","Rebuild after moving CSS files so resource ids update."],"tags":["xaml","xamlc","stylesheet","embedded-resource","resource-path","build-time"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}