{"record":{"id":"33db926fc189a5b6","repo":"microsoft/aspire","slug":"embedded-resource-name-not-found","errorCode":null,"errorMessage":"Embedded resource '{name}' not found.","messagePattern":"Embedded resource '(.+?)' not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs","lineNumber":709,"sourceCode":"    /// <inheritdoc />\n    public Dictionary<string, string> GenerateDistributedApplication(AtsContext context)\n    {\n        var files = new Dictionary<string, string>();\n\n        // Generate the capability-based aspire.py SDK\n        files[\"aspire_app.py\"] = GenerateAspireSdk(context);\n        files[\"pyproject.toml\"] = GetEmbeddedResource(\"pyproject.toml\");\n\n        return files;\n    }\n\n    private static string GetEmbeddedResource(string name)\n    {\n        var assembly = Assembly.GetExecutingAssembly();\n        var resourceName = $\"Aspire.Hosting.CodeGeneration.Python.Resources.{name}\";\n\n        using var stream = assembly.GetManifestResourceStream(resourceName)\n            ?? throw new InvalidOperationException($\"Embedded resource '{name}' not found.\");\n        using var reader = new StreamReader(stream);\n        return reader.ReadToEnd();\n    }\n\n    /// <summary>\n    /// Gets a valid Python method name from a capability method name.\n    /// Converts camelCase to snake_case.\n    /// Handles dotted names like \"EnvironmentContext.resource\" by extracting just the final part.\n    /// </summary>\n    private static string GetPythonMethodName(string methodName)\n    {\n        // Extract last component if dotted (e.g., \"Type.method\" -> \"method\")\n        var lastDot = methodName.LastIndexOf('.');\n        if (lastDot >= 0)\n        {\n            methodName = methodName[(lastDot + 1)..];\n        }\n","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs#L691-L727","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reinstall/restore the official Aspire.Hosting.CodeGeneration.Python package (or rebuild the repo from a clean state) so embedded resources are present.","Check the project file to confirm the referenced resource file exists under the Resources folder and is included as `<EmbeddedResource>`.","If building from source, run a clean rebuild; incremental builds can occasionally leave stale resource manifests.","Report the issue with the resource name from the message if it occurs with an official package build."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// caller-side sanity check when building from source\nvar names = typeof(AtsPythonCodeGenerator).Assembly.GetManifestResourceNames();\nbool ok = names.Any(n => n.StartsWith(\"Aspire.Hosting.CodeGeneration.Python.Resources.\"));","typeGuard":null,"tryCatchPattern":"try {\n  string script = GetEmbeddedResource(name);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"Embedded resource\")) {\n  // treat as broken package install; reinstall or report\n}","preventionTips":["Use official NuGet packages rather than hand-built copies.","Keep resource files and their csproj EmbeddedResource entries in sync when renaming.","Clean-rebuild when upgrading between package versions."],"tags":["python","code-generation","embedded-resource","packaging"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}