dotnet/maui · error · XamlParseException

Resource '{source}' not found.

Error message

Resource '{source}' not found.

What it means

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.

Source

Thrown at src/Controls/src/Build.Tasks/CompiledValueProviders/StyleSheetProvider.cs:60

				yield return Create(Call, module.ImportMethodReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.StyleSheets", "StyleSheet"),
																	   methodName: "FromString",
																	   parameterTypes: [("mscorlib", "System", "String")],
																	   isStatic: true));
			}
			else
			{
				var source = (sourceNode as ValueNode)?.Value as string;
				INode rootNode = node;
				while (rootNode is not ILRootNode)
					rootNode = rootNode.Parent;

				var rootTargetPath = RDSourceTypeConverter.GetPathForType(context, module, ((ILRootNode)rootNode).TypeReference);
				var uri = new Uri(source, UriKind.Relative);

				var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(uri, rootTargetPath);
				//fail early
				if (XamlCTask.GetResourceIdForPath(context.Cache, module, resourcePath) == null)
					throw new XamlParseException($"Resource '{source}' not found.", node);

				yield return Create(Ldstr, resourcePath); //resourcePath

				yield return Create(Ldtoken, module.ImportReference(((ILRootNode)rootNode).TypeReference));
				yield return Create(Call, module.ImportMethodReference(context.Cache, ("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
				yield return Create(Callvirt, module.ImportPropertyGetterReference(context.Cache, ("mscorlib", "System", "Type"), propertyName: "Assembly", flatten: true)); //assembly

				foreach (var instruction in node.PushXmlLineInfo(context))
					yield return instruction; //lineinfo

				yield return Create(Call, module.ImportMethodReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.StyleSheets", "StyleSheet"),
																	   methodName: "FromResource",
																	   parameterTypes: [("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo")],
																	   isStatic: true));
			}

			//the variable is of type `object`. fix that
			var vardef = new VariableDefinition(module.ImportReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.StyleSheets", "StyleSheet")));

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Set the .css file's build action to 'MauiCss' (or 'EmbeddedResource') so it is embedded.
  2. Match the Source path to the actual logical resource id (default namespace + folders, dot-separated).
  3. Confirm the file is included for all target frameworks in the build.
  4. Verify casing exactly matches between Source and the file on disk.

Example fix

// before
<!-- file at Styles/app.css, build action = None -->
<StyleSheet Source="app.css" />
// after
<!-- set build action = MauiCss -->
<StyleSheet Source="Styles/app.css" />
Defensive patterns

Strategy: validation

Validate before calling

// Before building, confirm the embedded resource id exists
static bool CssResourceExists(Assembly asm, string resourcePath) {
    var ids = asm.GetManifestResourceNames();
    return ids.Any(n => n.Equals(resourcePath, StringComparison.Ordinal)
                     || n.EndsWith("." + resourcePath));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/6e262a51bafc42fa. Report an issue: GitHub.