{"record":{"id":"ef1af05366b39587","repo":"microsoft/aspire","slug":"invalid-entrypoint-type","errorCode":null,"errorMessage":"Invalid entrypoint type.","messagePattern":"Invalid entrypoint type\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs","lineNumber":1056,"sourceCode":"    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(entrypoint);\n\n        // Get or create the virtual environment from the annotation\n        if (!builder.Resource.TryGetLastAnnotation<PythonEnvironmentAnnotation>(out var pythonEnv) ||\n            pythonEnv.VirtualEnvironment is null)\n        {\n            throw new InvalidOperationException(\"Cannot set entrypoint: Python environment annotation with virtual environment not found.\");\n        }\n\n        var virtualEnvironment = pythonEnv.VirtualEnvironment;\n\n        // Determine the new command based on entrypoint type\n        var command = entrypointType switch\n        {\n            EntrypointType.Executable => virtualEnvironment.GetExecutable(entrypoint),\n            EntrypointType.Script or EntrypointType.Module => virtualEnvironment.GetExecutable(\"python\"),\n            _ => throw new ArgumentOutOfRangeException(nameof(entrypointType), entrypointType, \"Invalid entrypoint type.\")\n        };\n\n        // Update the command inline\n        builder.WithCommand(command);\n        builder.WithAnnotation(new PythonEntrypointAnnotation\n        {\n            Type = entrypointType,\n            Entrypoint = entrypoint\n        },\n        ResourceAnnotationMutationBehavior.Replace);\n\n        // Arguments already registered for the previous entrypoint may be invalid for the replacement. Keep this\n        // clear in the ordinary argument segment so arguments registered after WithEntrypoint are preserved.\n        builder.WithArgs(static context => context.Args.Clear());\n\n        builder.WithLaunchToolArgs(static context =>\n        {\n            if (!context.Resource.TryGetLastAnnotation<PythonEntrypointAnnotation>(out var existingAnnotation))","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs#L1038-L1074","documentation":"WithEntrypoint maps the supplied EntrypointType to a command via a switch expression covering Executable, Script, and Module. Any other value reaches the default arm and throws ArgumentOutOfRangeException naming entrypointType.","triggerScenarios":"Passing an EntrypointType value outside the three supported members to WithEntrypoint — typically from an invalid cast, uninitialized enum value, or a value from a mismatched package version.","commonSituations":"Casting int values to EntrypointType from external config; deserializing enum from user input; version drift between client code and the Aspire.Hosting.Python package introducing new enum members.","solutions":["Pass a valid EntrypointType: EntrypointType.Executable, EntrypointType.Script, or EntrypointType.Module.","Validate any config-driven enum value with Enum.IsDefined before casting.","Align Aspire.Hosting.Python package versions across projects.","Parse with Enum.TryParse<EntrypointType> and reject unknown values early."],"exampleFix":"// before\nvar type = (EntrypointType)configValue; // 7, undefined\npy.WithEntrypoint(type, \"tool.py\");\n// after\nvar type = Enum.IsDefined(typeof(EntrypointType), configValue) ? (EntrypointType)configValue : EntrypointType.Script;\npy.WithEntrypoint(type, \"tool.py\");","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(entrypointType))\n    throw new ArgumentOutOfRangeException(nameof(entrypointType), $\"Unsupported EntrypointType: {entrypointType}\");","typeGuard":"static bool TryParseEntrypointType(object raw, out EntrypointType value)\n{\n    value = default;\n    return raw is int i && Enum.IsDefined(typeof(EntrypointType), i)\n        ? (value = (EntrypointType)i) is var _\n        : Enum.TryParse(raw?.ToString(), out value) && Enum.IsDefined(value);\n}","tryCatchPattern":"try\n{\n    pyApp.WithEntrypoint(entrypointType, entrypoint);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogError(ex, \"entrypointType must be Executable, Script, or Module.\");\n}","preventionTips":["Only pass literal EntrypointType.Executable/Script/Module values.","Use Enum.IsDefined/Enum.TryParse when sourcing values from config.","Avoid unchecked casts from int to EntrypointType."],"tags":["csharp","aspire","python","enum","argument-out-of-range"],"backgroundTag":"invalid-enum-argument","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"}