AvaloniaUI/Avalonia · error · InvalidOperationException

Could not find manifest resource stream '{_name}',

Error message

Could not find manifest resource stream '{_name}',

What it means

AssemblyResourceDescriptor.GetStream() resolves a named manifest resource from an Assembly via GetManifestResourceStream(_name) and throws InvalidOperationException when that call returns null, i.e. the assembly has no embedded resource matching the stored name. It is the low-level path the Avalonia asset loader uses to fetch an assembly-embedded (default C# build action 'Embedded Resource') asset stream. A null here means the resource name and the assembly's actual manifest resources do not line up.

Source

Thrown at src/Avalonia.Base/Platform/Internal/AssetDescriptor.cs:27

    Stream GetStream();
    Assembly Assembly { get; }
}

internal class AssemblyResourceDescriptor : IAssetDescriptor
{
    private readonly Assembly _asm;
    private readonly string _name;

    public AssemblyResourceDescriptor(Assembly asm, string name)
    {
        _asm = asm;
        _name = name;
    }

    public Stream GetStream()
    {
        var s = _asm.GetManifestResourceStream(_name);
        return s ?? throw new InvalidOperationException($"Could not find manifest resource stream '{_name}',");
    }

    public Assembly Assembly => _asm;
}
        
internal class AvaloniaResourceDescriptor : IAssetDescriptor
{
    private readonly int _offset;
    private readonly int _length;
    public Assembly Assembly { get; }

    public AvaloniaResourceDescriptor(Assembly asm, int offset, int length)
    {
        _offset = offset;
        _length = length;
        Assembly = asm;
    }

View on GitHub (pinned to 11c5427268)

Solutions

  1. Verify the resource exists at runtime: inspect assembly.GetManifestResourceNames() and confirm _name is present; fix the build action or path to match.
  2. Ensure the file's MSBuild build action is 'Embedded Resource' (for manifest resources) or 'AvaloniaResource' (for avares), rebuild, and confirm it is emitted into the assembly.
  3. If trimming/linking is on, add the resource (or its assembly) to the linker 'TrimmerRootDescriptor' / Preserve list so the embedded resource is not stripped.
  4. Check that the assembly passed into AssemblyResourceDescriptor is the one that actually contains the resource, not a referenced facade assembly.

Example fix

// before: wrong build action, resource missing from manifest
var s = _asm.GetManifestResourceStream("MyApp.Assets.icon.png"); // null

<!-- after: set build action to 'Embedded Resource' in the .csproj/properties, then -->
var names = _asm.GetManifestResourceNames();
var s = _asm.GetManifestResourceStream(names.First(n => n.EndsWith("icon.png")));
Defensive patterns

Strategy: validation

Validate before calling

string name = "MyNamespace.Assets.icon.png";
bool present = _asm.GetManifestResourceNames().Contains(name);
if (!present) return; // or log and degrade
using var s = _asm.GetManifestResourceStream(name)!;

Type guard

bool ResourceExists(Assembly asm, string name) => asm.GetManifestResourceNames().Contains(name);

Prevention

When it happens

Trigger: Calling IAssetDescriptor.GetStream() on an AssetDescriptor produced for a regular manifest resource after the loader resolved the URI to an (asm, name) pair, where _asm.GetManifestResourceStream(_name) yields null. Happens through StandardAssetLoader.Open/OpenAndGetAssembly when the resolved descriptor is an AssemblyResourceDescriptor whose name is not present in _asm.GetManifestResourceNames().

Common situations: The resource was added with the wrong build action (e.g. 'None'/'Content' instead of 'Embedded Resource'), the file was renamed/moved after the asset reference was compiled in, an IL linker/trimmer removed the embedded resource, or the wrong assembly was registered with the asset loader so the name lookup happens against an assembly that never owned it.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/4c6447e7e38de6ca. Report an issue: GitHub.