{"record":{"id":"44e4ee5ee05e818b","repo":"AvaloniaUI/Avalonia","slug":"the-resource-uri-could-not-be-found","errorCode":null,"errorMessage":"The resource {uri} could not be found.","messagePattern":"The resource (.+?) could not be found\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Platform/StandardAssetLoader.cs","lineNumber":92,"sourceCode":"    /// </summary>\n    /// <param name=\"uri\">The URI.</param>\n    /// <param name=\"baseUri\">\n    /// A base URI to use if <paramref name=\"uri\"/> is relative.\n    /// </param>\n    /// <returns>\n    /// The stream containing the resource contents together with the assembly.\n    /// </returns>\n    /// <exception cref=\"FileNotFoundException\">\n    /// The asset could not be found.\n    /// </exception>\n    public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null)\n    {\n        if (TryGetAsset(uri, baseUri, out var assetDescriptor))\n        {\n            return (assetDescriptor.GetStream(), assetDescriptor.Assembly);\n        }\n\n        throw new FileNotFoundException($\"The resource {uri} could not be found.\");\n    }\n\n    public Assembly? GetAssembly(Uri uri, Uri? baseUri)\n    {\n        if (!uri.IsAbsoluteUri && baseUri != null)\n        {\n            uri = new Uri(baseUri, uri);\n        }\n\n        if (TryGetAssembly(uri, out var assemblyDescriptor))\n        {\n            return assemblyDescriptor.Assembly;\n        }\n\n        return null;\n    }\n\n    /// <summary>","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Platform/StandardAssetLoader.cs#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: relative uri, no base, asset not found\nusing var s = AssetLoader.Open(new Uri(\"Assets/icon.png\"));\n\n// after: absolute avares URI with assembly + correct build action\nusing var s = AssetLoader.Open(new Uri(\"avares://MyAssembly/Assets/icon.png\"));","handlingStrategy":"try-catch","validationCode":"var uri = new Uri(\"avares://MyAssembly/Assets/icon.png\");\nif (!AssetLoader.Exists(uri)) return;","typeGuard":"bool AssetResolvable(Uri uri, Uri? baseUri = null) => Avalonia.Platform.AssetLoader.GetAsset(uri, baseUri) is not null; // or use the public Exists API","tryCatchPattern":"try { using var s = AssetLoader.Open(uri); }\ncatch (FileNotFoundException ex) { /* log missing asset, fall back to bundled default */ }","preventionTips":["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."],"tags":["avalonia","assets","asset-loader","uri","resource-loading"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}