microsoft/aspire · error · ArgumentException
Array params contains empty item
Error message
Array params contains empty item: [{values}] What it means
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.
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.
Example fix
// before
builder.AddPythonApp("py", "main.py", "--flag", "");
// after
builder.AddPythonApp("py", "main.py", "--flag", "--other"); Defensive patterns
Strategy: validation
Validate before calling
if (args.Any(a => string.IsNullOrEmpty(a)))
throw new InvalidOperationException("scriptArgs contains an empty entry."); Try / catch
try
{
builder.AddPythonApp("py", "main.py", args);
}
catch (ArgumentException ex)
{
logger.LogError(ex, "Empty entry in python args: {Args}", ex.Message);
} Prevention
- 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.
When it happens
Trigger: Passing an array containing an empty string element to AddPythonApp, e.g. new[] { "--flag", "" } or an argument computed from an empty environment variable.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Array params contains null item
- Cannot configure debugging: Python entrypoint annotation…
- Cannot set entrypoint: Python environment annotation with…
- Cannot update virtual environment: Python entrypoint…
- Invalid entrypoint type.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/dd43596f3c0b3eed.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs:745
case EntrypointType.Executable:
stage.Entrypoint([entrypoint]);
break;
}
}
private static void ThrowIfNullOrContainsIsNullOrEmpty(string[] scriptArgs)
{
ArgumentNullException.ThrowIfNull(scriptArgs);
foreach (var scriptArg in scriptArgs)
{
if (string.IsNullOrEmpty(scriptArg))
{
var values = string.Join(", ", scriptArgs);
if (scriptArg is null)
{
throw new ArgumentNullException(nameof(scriptArgs), $"Array params contains null item: [{values}]");
}
throw new ArgumentException($"Array params contains empty item: [{values}]", nameof(scriptArgs));
}
}
}
/// <summary>
/// Resolves the default virtual environment path by checking multiple candidate locations.
/// </summary>
/// <param name="builder">The distributed application builder.</param>
/// <param name="appDirectory">The Python app directory (relative to AppHost).</param>
/// <param name="virtualEnvironmentPath">The relative virtual environment path (e.g., ".venv").</param>
/// <returns>The resolved virtual environment path.</returns>
private static string ResolveDefaultVirtualEnvironmentPath(IDistributedApplicationBuilder builder, string appDirectory, string virtualEnvironmentPath)
{
var appDirectoryFullPath = Path.GetFullPath(appDirectory, builder.AppHostDirectory);
// Walk up from the Python app directory looking for the virtual environment
// Stop at the AppHost's parent directory to avoid picking up unrelated venvs
var appHostParentDirectory = Path.GetDirectoryName(builder.AppHostDirectory);View on GitHub (pinned to 25830f84bd)