{"record":{"id":"dd43596f3c0b3eed","repo":"microsoft/aspire","slug":"array-params-contains-empty-item-values","errorCode":null,"errorMessage":"Array params contains empty item: [{values}]","messagePattern":"Array params contains empty item: \\[(.+?)\\]","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs","lineNumber":745,"sourceCode":"            case EntrypointType.Executable:\n                stage.Entrypoint([entrypoint]);\n                break;\n        }\n    }\n\n    private static void ThrowIfNullOrContainsIsNullOrEmpty(string[] scriptArgs)\n    {\n        ArgumentNullException.ThrowIfNull(scriptArgs);\n        foreach (var scriptArg in scriptArgs)\n        {\n            if (string.IsNullOrEmpty(scriptArg))\n            {\n                var values = string.Join(\", \", scriptArgs);\n                if (scriptArg is null)\n                {\n                    throw new ArgumentNullException(nameof(scriptArgs), $\"Array params contains null item: [{values}]\");\n                }\n                throw new ArgumentException($\"Array params contains empty item: [{values}]\", nameof(scriptArgs));\n            }\n        }\n    }\n\n    /// <summary>\n    /// Resolves the default virtual environment path by checking multiple candidate locations.\n    /// </summary>\n    /// <param name=\"builder\">The distributed application builder.</param>\n    /// <param name=\"appDirectory\">The Python app directory (relative to AppHost).</param>\n    /// <param name=\"virtualEnvironmentPath\">The relative virtual environment path (e.g., \".venv\").</param>\n    /// <returns>The resolved virtual environment path.</returns>\n    private static string ResolveDefaultVirtualEnvironmentPath(IDistributedApplicationBuilder builder, string appDirectory, string virtualEnvironmentPath)\n    {\n        var appDirectoryFullPath = Path.GetFullPath(appDirectory, builder.AppHostDirectory);\n\n        // Walk up from the Python app directory looking for the virtual environment\n        // Stop at the AppHost's parent directory to avoid picking up unrelated venvs\n        var appHostParentDirectory = Path.GetDirectoryName(builder.AppHostDirectory);","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs#L727-L763","documentation":"AddPythonApp validates its scriptArgs collection via ThrowIfNullOrContainsIsNullOrEmpty. If any element of scriptArgs is an empty string, it throws ArgumentException naming scriptArgs and including the full argument list in the message.","triggerScenarios":"Passing an array containing an empty string element to AddPythonApp, e.g. new[] { \"--flag\", \"\" } or an argument computed from an empty environment variable.","commonSituations":"Arguments read from unset environment variables or empty config values; string interpolation producing \"\" when a value is missing; users intending a bare flag by passing an empty string.","solutions":["Inspect the args list in the message and remove or replace the empty string entry.","Provide the actual argument value the empty string was meant to represent.","Filter empties before calling: args = candidateArgs.Where(a => !string.IsNullOrEmpty(a)).ToArray().","If a bare flag was intended, pass the flag token itself (e.g. \"--verbose\") rather than an empty string."],"exampleFix":"// before\nbuilder.AddPythonApp(\"py\", \"main.py\", \"--flag\", \"\");\n// after\nbuilder.AddPythonApp(\"py\", \"main.py\", \"--flag\", \"--other\");","handlingStrategy":"validation","validationCode":"if (args.Any(a => string.IsNullOrEmpty(a)))\n    throw new InvalidOperationException(\"scriptArgs contains an empty entry.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.AddPythonApp(\"py\", \"main.py\", args);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Empty entry in python args: {Args}\", ex.Message);\n}","preventionTips":["Filter with Where(a => !string.IsNullOrEmpty(a)) before passing script args.","Provide default values for arguments sourced from empty env vars or config.","Pass bare flags as their own token instead of empty strings."],"tags":["csharp","aspire","python","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}