microsoft/aspire · error · InvalidOperationException

Embedded resource ' ' not found.

Error message

Embedded resource '{name}' not found.

What it means

The Python code generator loads template/preamble files (such as generated runtime support scripts) from embedded resources inside the Aspire.Hosting.CodeGeneration.Python assembly. `GetEmbeddedResource` throws this InvalidOperationException when no manifest resource matches the expected name `Aspire.Hosting.CodeGeneration.Python.Resources.{name}`. This is an internal packaging failure, not something a normal user's code can cause directly.

Solutions

  1. Reinstall/restore the official Aspire.Hosting.CodeGeneration.Python package (or rebuild the repo from a clean state) so embedded resources are present.
  2. Check the project file to confirm the referenced resource file exists under the Resources folder and is included as `<EmbeddedResource>`.
  3. If building from source, run a clean rebuild; incremental builds can occasionally leave stale resource manifests.
  4. Report the issue with the resource name from the message if it occurs with an official package build.
Defensive patterns

Strategy: try-catch

Validate before calling

// caller-side sanity check when building from source
var names = typeof(AtsPythonCodeGenerator).Assembly.GetManifestResourceNames();
bool ok = names.Any(n => n.StartsWith("Aspire.Hosting.CodeGeneration.Python.Resources."));

Try / catch

try {
  string script = GetEmbeddedResource(name);
} catch (InvalidOperationException ex) when (ex.Message.Contains("Embedded resource")) {
  // treat as broken package install; reinstall or report
}

Prevention

When it happens

Trigger: Calling GenerateDistributedApplication (which calls GetEmbeddedResource) with a resource name that is not embedded in the assembly — e.g. the csproj ItemGroup with `<EmbeddedResource Include="Resources/...">` is missing the file, the file was deleted/renamed, or the assembly was built without the resources.

Common situations: Using a custom or locally modified build of the package where resource files were stripped; a packaging bug or regression that renamed a resource; running from an unofficial NuGet build where the embedded resources were not included.

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/33db926fc189a5b6. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs:709

    /// <inheritdoc />
    public Dictionary<string, string> GenerateDistributedApplication(AtsContext context)
    {
        var files = new Dictionary<string, string>();

        // Generate the capability-based aspire.py SDK
        files["aspire_app.py"] = GenerateAspireSdk(context);
        files["pyproject.toml"] = GetEmbeddedResource("pyproject.toml");

        return files;
    }

    private static string GetEmbeddedResource(string name)
    {
        var assembly = Assembly.GetExecutingAssembly();
        var resourceName = $"Aspire.Hosting.CodeGeneration.Python.Resources.{name}";

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

    /// <summary>
    /// Gets a valid Python method name from a capability method name.
    /// Converts camelCase to snake_case.
    /// Handles dotted names like "EnvironmentContext.resource" by extracting just the final part.
    /// </summary>
    private static string GetPythonMethodName(string methodName)
    {
        // Extract last component if dotted (e.g., "Type.method" -> "method")
        var lastDot = methodName.LastIndexOf('.');
        if (lastDot >= 0)
        {
            methodName = methodName[(lastDot + 1)..];
        }

View on GitHub (pinned to 25830f84bd)