AvaloniaUI/Avalonia · error · FileNotFoundException
The resource {uri} could not be found.
Error message
The resource {uri} could not be found. What it means
StandardAssetLoader.OpenAndGetAssembly(uri) attempts TryGetAsset and, if no asset descriptor is produced for the (uri, baseUri) pair, throws FileNotFoundException. This is the top-level asset loader entry point: every higher-level 'open this resource URI' call funnels here, so this is the canonical 'Avalonia could not resolve your asset URI' error.
Source
Thrown at src/Avalonia.Base/Platform/StandardAssetLoader.cs:92
/// </summary>
/// <param name="uri">The URI.</param>
/// <param name="baseUri">
/// A base URI to use if <paramref name="uri"/> is relative.
/// </param>
/// <returns>
/// The stream containing the resource contents together with the assembly.
/// </returns>
/// <exception cref="FileNotFoundException">
/// The asset could not be found.
/// </exception>
public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null)
{
if (TryGetAsset(uri, baseUri, out var assetDescriptor))
{
return (assetDescriptor.GetStream(), assetDescriptor.Assembly);
}
throw new FileNotFoundException($"The resource {uri} could not be found.");
}
public Assembly? GetAssembly(Uri uri, Uri? baseUri)
{
if (!uri.IsAbsoluteUri && baseUri != null)
{
uri = new Uri(baseUri, uri);
}
if (TryGetAssembly(uri, out var assemblyDescriptor))
{
return assemblyDescriptor.Assembly;
}
return null;
}
/// <summary>View on GitHub (pinned to 11c5427268)
Solutions
- Use an absolute avares:// URI with the correct assembly name and forward-slash path: new Uri("avares://MyAssembly/Assets/icon.png").
- Confirm the asset's build action is AvaloniaResource and the owning assembly is registered with the loader (AssetLoader.SetDefaultAssembly / RegisterResamplerPng etc., or WithAssemblyDescriptor on the loader).
- When using relative URIs, always pass a valid baseUri so the loader can resolve the absolute path; null baseUri with a relative uri cannot be resolved.
- Check spelling and casing of every path segment; on case-sensitive platforms a wrong-case path resolves at design time but fails here.
Example fix
// before: relative uri, no base, asset not found
using var s = AssetLoader.Open(new Uri("Assets/icon.png"));
// after: absolute avares URI with assembly + correct build action
using var s = AssetLoader.Open(new Uri("avares://MyAssembly/Assets/icon.png")); Defensive patterns
Strategy: try-catch
Validate before calling
var uri = new Uri("avares://MyAssembly/Assets/icon.png");
if (!AssetLoader.Exists(uri)) return; Type guard
bool AssetResolvable(Uri uri, Uri? baseUri = null) => Avalonia.Platform.AssetLoader.GetAsset(uri, baseUri) is not null; // or use the public Exists API
Try / catch
try { using var s = AssetLoader.Open(uri); }
catch (FileNotFoundException ex) { /* log missing asset, fall back to bundled default */ } Prevention
- Use absolute 'avares://Assembly/...' URIs and pass a baseUri for relative ones.
- Check AssetLoader.Exists(uri) before opening when the asset is optional.
- Register every asset-bearing assembly with the loader at startup.
- Keep asset paths and casing consistent across design and runtime.
When it happens
Trigger: Calling OpenAndGetAssembly / Open / GetAsset with a URI whose scheme, path, or owning assembly do not match any registered asset. TryGetAsset returns false when no resolver matches 'resm:'/'avares:' or the resolved path is absent from the assembly's resource index.
Common situations: Missing or wrong URI prefix (using a relative path instead of 'avares://AssemblyName/...'), typo in assembly name or asset path, asset assembly not registered with the asset loader (WithAssemblyDescriptor not added), asset built into the wrong assembly, or case-sensitivity mismatch on case-sensitive filesystems/builds.
Related errors
- Could not find manifest resource stream '{_name}',
- Could not find manifest resource stream '{Constants.Avalonia
- File path is expected to be an absolute link with "file" or
- Folder path is expected to be an absolute link with "file" o
- Duration value cannot be negative.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/44e4ee5ee05e818b.
Report an issue: GitHub.