microsoft/aspire · error · InvalidOperationException

Embedded resource ' ' not found.

Error message

Embedded resource '{name}' not found.

What it means

The TypeScript code generator's EmbeddedResources.Read helper loads template files (like base.mts) from embedded resources in the assembly under the configured ResourceNamespace. It throws this InvalidOperationException when GetManifestResourceStream returns null, i.e. no embedded resource matches `{ResourceNamespace}.{name}`. This is an internal invariant failure indicating the assembly was built or packaged without its resource files.

Solutions

  1. Reinstall/restore the official package or clean-rebuild the repo so the embedded resources are included.
  2. Verify the referenced resource file exists and is marked `<EmbeddedResource>` in the TypeScript code generation project.
  3. Compare the assembly's manifest resource names with the ResourceNamespace constant to find naming mismatches when building from source.
  4. Report the issue with the exact resource name if an official package build triggers it.
Defensive patterns

Strategy: try-catch

Validate before calling

const names = typeof(EmbeddedResources).Assembly.GetManifestResourceNames();
const exists = names.some(n => n === `${ResourceNamespace}.${name}`);

Try / catch

try {
  const template = EmbeddedResources.Read(name);
} catch (err) {
  if (err instanceof Error && err.message.includes('Embedded resource')) {
    // broken build/package; reinstall and report
  }
}

Prevention

When it happens

Trigger: Invoking EmbeddedResources.Read (via code generation in GenerateDistributedApplication or related paths) with a name whose corresponding file is not embedded in the assembly — missing/renamed resource file, removed csproj EmbeddedResource entry, or stripped build.

Common situations: Running a locally modified or unofficial build of the package; a packaging regression that dropped Resources/*.mts; corrupt NuGet package cache after a partial download.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/265e83cf3936a64f. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.CodeGeneration.TypeScript/EmbeddedResources.cs:26

/// <c>Aspire.Hosting.CodeGeneration.TypeScript</c> assembly.
/// </summary>
internal static class EmbeddedResources
{
    private const string ResourceNamespace = "Aspire.Hosting.CodeGeneration.TypeScript.Resources";

    /// <summary>
    /// Reads the contents of an embedded resource by file name (e.g. <c>"eslint.config.mjs"</c>).
    /// </summary>
    /// <param name="name">The resource file name as it lives under <c>Resources/</c>.</param>
    /// <returns>The UTF-8 text content of the resource.</returns>
    /// <exception cref="InvalidOperationException">Thrown when the resource is not embedded.</exception>
    public static string Read(string name)
    {
        var assembly = typeof(EmbeddedResources).Assembly;
        var resourceName = $"{ResourceNamespace}.{name}";

        using var stream = assembly.GetManifestResourceStream(resourceName)
            ?? throw new InvalidOperationException($"Embedded resource '{name}' not found.");
        using var reader = new StreamReader(stream);
        return reader.ReadToEnd();
    }
}

View on GitHub (pinned to 25830f84bd)