microsoft/aspire · error · InvalidOperationException
Process command success exit codes must contain at least…
Error message
Process command success exit codes must contain at least one value.
What it means
When a process command executes, Aspire decides success by checking the process exit code against the configured SuccessExitCodes collection. If that collection is null or empty no exit code could ever be considered successful, so Aspire throws InvalidOperationException instead of executing a command that can never succeed.
Solutions
- Populate SuccessExitCodes with at least one code, typically new[] { 0 } or the process's documented success codes
- If building the set dynamically, validate it is non-empty (or fall back to [0]) before assigning
- Remove the explicit empty SuccessExitCodes assignment to let the default apply
Example fix
// before options.SuccessExitCodes = []; // after options.SuccessExitCodes = [0];
Defensive patterns
Strategy: validation
Validate before calling
if (options.SuccessExitCodes is null || options.SuccessExitCodes.Count == 0)
options.SuccessExitCodes = [0]; Type guard
bool HasSuccessCodes(ICollection<int>? codes) => codes is { Count: > 0 }; Try / catch
try { /* configure command */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("success exit codes")) { /* supply default codes and retry */ } Prevention
- Always initialize SuccessExitCodes with at least the standard code 0
- Validate dynamically-built exit-code sets before assignment
When it happens
Trigger: Configuring a process command (e.g. WithCommand with startCommandOptions or a custom success-exit-codes callback path) where CommandOptions.SuccessExitCodes is left null or set to an empty set/array.
Common situations: Building success exit codes from a list populated conditionally at runtime so it ends up empty; passing an empty HashSet/array by mistake; forgetting the default is non-empty but supplying an explicit empty collection.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- At least one process command success exit code must be…
- Foundry hosted agent for target resource
- Foundry hosted agent for target resource
- HTTP command request content type cannot be specified…
- Process command ' ' environment variable ' ' requires a…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/e0ec7c7d7dc08fac.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ResourceBuilderExtensions.cs:3499
return GetDefaultProcessCommandResult(processCommandSpec.ExecutablePath, processResult, commandOptions);
}
internal static ExecuteCommandResult GetDefaultProcessCommandResult(string executablePath, ProcessResult processResult, ProcessCommandOptions commandOptions)
{
var formattedOutput = processResult.GetFormattedOutput(commandOptions.MaxOutputLineCount);
var resultData = string.IsNullOrEmpty(formattedOutput)
? null
: new CommandResultData
{
Value = formattedOutput,
Format = CommandResultFormat.Text,
DisplayImmediately = commandOptions.DisplayImmediately
};
var successExitCodes = commandOptions.SuccessExitCodes;
if (successExitCodes is null || successExitCodes.Count == 0)
{
throw new InvalidOperationException("Process command success exit codes must contain at least one value.");
}
if (successExitCodes.Contains(processResult.ExitCode))
{
return resultData is null
? CommandResults.Success()
: new ExecuteCommandResult { Success = true, Data = resultData };
}
var message = $"Command '{executablePath}' exited with code {processResult.ExitCode}, which is not in the configured success exit codes [{string.Join(", ", successExitCodes)}].";
return resultData is null
? CommandResults.Failure(message)
: CommandResults.Failure(message, resultData);
}
#pragma warning restore ASPIREPROCESSCOMMAND001
View on GitHub (pinned to 25830f84bd)