AvaloniaUI/Avalonia · error · InvalidOperationException

Could not find manifest resource stream '{Constants.Avalonia

Error message

Could not find manifest resource stream '{Constants.AvaloniaResourceName}',

What it means

AvaloniaResourceDescriptor.GetStream() reads from the single combined 'avalonia.resources' blob that Avalonia's build task generates, addressed by an (offset, length) slice. It throws InvalidOperationException when Assembly.GetManifestResourceStream(Constants.AvaloniaResourceName) returns null, i.e. the combined blob was never embedded into the assembly. Unlike [340], the resource name is a fixed constant, so failure always means the avalonia.resources blob itself is absent.

Source

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

}
        
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;
    }

    public Stream GetStream()
    {
        var s = Assembly.GetManifestResourceStream(Constants.AvaloniaResourceName) ??
                throw new InvalidOperationException($"Could not find manifest resource stream '{Constants.AvaloniaResourceName}',");
        return new SlicedStream(s, _offset, _length);
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Confirm the assembly contains the blob at runtime: assembly.GetManifestResourceNames().Contains("avalonia.resources") must be true; if false, rebuild with the Avalonia targets active.
  2. Verify the asset's MSBuild build action is 'AvaloniaResource' and the project imports the Avalonia targets / uses the Avalonia SDK so the combined blob is generated.
  3. Make sure the owning assembly of the avares:// URI is the one registered with the asset loader and is the freshly built output.
  4. If publishing trimmed, root the 'avalonia.resources' manifest entry or disable trimming for asset-bearing assemblies.

Example fix

// before: asset referenced via avares:// but blob missing
var s = asm.GetManifestResourceStream("avalonia.resources"); // null -> throw

// after: ensure build action and targets
<!-- .csproj -->
<ItemGroup>
  <AvaloniaResource Include="Assets\**\*" />
</ItemGroup>
<!-- and confirm: -->
bool ok = asm.GetManifestResourceNames().Contains("avalonia.resources");
Defensive patterns

Strategy: validation

Validate before calling

bool hasBlob = asm.GetManifestResourceNames().Contains("avalonia.resources");
if (!hasBlob) { /* rebuild / fix build action */ return; }

Type guard

bool HasAvaloniaResourcesBlob(Assembly asm) => asm.GetManifestResourceNames().Contains("avalonia.resources");

Prevention

When it happens

Trigger: Resolving any 'avares://' asset whose owning assembly was indexed by the Avalonia build task but the final assembly does not contain the 'avalonia.resources' manifest entry, so the descriptor's SlicedStream cannot be opened. Triggered through the standard asset loader Open/GetStream path for an AvaloniaResource-backed asset.

Common situations: The project references Avalonia but lacks the Avalonia.Resource build items / AvaloniaGenerateReswowInput or the build task didn't run (older SDK, custom .csproj that overrides targets), the resource file's build action is wrong, source generators/targets were disabled, or the assembly is being loaded from a location that wasn't rebuilt after switching to the avares resource model.

Related errors


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