microsoft/aspire · error · InvalidOperationException

Embedded resource 'microvenv.py' not found.

Error message

Embedded resource 'microvenv.py' not found.

What it means

When creating a Python virtual environment for generated Python AppHosts, the code loads the embedded `microvenv.py` bootstrap script from the Aspire.Hosting.CodeGeneration.Python assembly. `LoadMicrovenvScript` throws this InvalidOperationException if the embedded resource `Aspire.Hosting.CodeGeneration.Python.Resources.microvenv.py` is missing from the assembly. This indicates a broken or incomplete build/packaging of the library.

Solutions

  1. Clear the NuGet cache for the package and restore the official Aspire.Hosting.CodeGeneration.Python package (dotnet nuget locals all --clear, then restore).
  2. If building from source, do a clean rebuild so Resources/microvenv.py is embedded again (verify the csproj lists it as EmbeddedResource).
  3. Verify the resource exists in the deployed assembly with a tool like ILSpy/ildasm before filing a bug.
  4. Report the issue with package version and RID if the official package is missing the resource.
Defensive patterns

Strategy: try-catch

Validate before calling

var hasMicrovenv = typeof(PythonLanguageSupport).Assembly
  .GetManifestResourceNames()
  .Contains("Aspire.Hosting.CodeGeneration.Python.Resources.microvenv.py");

Try / catch

try {
  string script = LoadMicrovenvScript();
} catch (InvalidOperationException ex) when (ex.Message.Contains("microvenv.py")) {
  // reinstall the package / fail with a clear 'broken install' message
}

Prevention

When it happens

Trigger: Code path that creates a Python environment (via LoadMicrovenvScript, invoked during Python AppHost provisioning) running against an assembly that does not contain the microvenv.py embedded resource.

Common situations: Using a stripped or third-party rebuild of the package; a broken NuGet package cache or partially extracted package; building the repo with resources excluded by custom build settings.

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

Appendix: source

Thrown at src/Aspire.Hosting.CodeGeneration.Python/PythonLanguageSupport.cs:304

            if (!process.WaitForExit(5000))
            {
                return false;
            }

            return process.ExitCode == 0;
        }
        catch
        {
            return false;
        }
    }

    private static string LoadMicrovenvScript()
    {
        using var stream = Assembly.GetExecutingAssembly()
            .GetManifestResourceStream("Aspire.Hosting.CodeGeneration.Python.Resources.microvenv.py")
            ?? throw new InvalidOperationException("Embedded resource 'microvenv.py' not found.");
        using var reader = new StreamReader(stream);
        return reader.ReadToEnd();
    }
}

View on GitHub (pinned to 25830f84bd)