microsoft/aspire · error · InvalidOperationException

ASPIRE_TERMINAL_HOST_INVOCATION_ARGS has unterminated

Error message

ASPIRE_TERMINAL_HOST_INVOCATION_ARGS has unterminated {(inDouble ? "double" : "single")} quote.

What it means

ParseInvocationArgs tokenizes the ASPIRE_TERMINAL_HOST_INVOCATION_ARGS environment variable using shell-like quote rules (double and single quotes, backslash escapes). If the value ends while a quote is still open, the parser cannot determine argument boundaries and throws InvalidOperationException naming which quote type was unterminated.

Solutions

  1. Fix ASPIRE_TERMINAL_HOST_INVOCATION_ARGS so every quote is paired, or remove quotes entirely if arguments contain no spaces.
  2. Escape embedded quotes with backslash (\" and \\) instead of nesting quotes.
  3. Print/log the variable value and count quotes to find the unbalanced one.
  4. Avoid quotes by splitting arguments so each one is a separate simple token.

Example fix

// before (unterminated single quote)
ASPIRE_TERMINAL_HOST_INVOCATION_ARGS=--project 'MyApp

// after
ASPIRE_TERMINAL_HOST_INVOCATION_ARGS=--project MyApp
Defensive patterns

Strategy: validation

Validate before calling

var args = Environment.GetEnvironmentVariable("ASPIRE_TERMINAL_HOST_INVOCATION_ARGS");
if (args is not null && (args.Count(c => c == '"') % 2 != 0 || args.Count(c => c == '\'') % 2 != 0))
{
    throw new FormatException("ASPIRE_TERMINAL_HOST_INVOCATION_ARGS has an unbalanced quote.");
}

Try / catch

try
{
    ParseInvocationArgs(raw);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("unterminated"))
{
    logger.LogError(ex, "Fix quoting in ASPIRE_TERMINAL_HOST_INVOCATION_ARGS: {Value}", raw);
}

Prevention

When it happens

Trigger: Setting ASPIRE_TERMINAL_HOST_INVOCATION_ARGS with an odd number of unescaped double (") or single (') quotes, e.g. "--verbose 'value" — the value ends while the parser is still inside a quoted section.

Common situations: Hand-editing the env var in launchSettings.json or shell export and dropping a closing quote; interpolating values that themselves contain quotes; copying a shell command with quotes into the variable without escaping; platform quoting differences (Windows vs bash).

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/e027287a650f86a0. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/Lifecycle/TerminalHostEventingSubscriber.cs:209

                case ' ':
                case '\t':
                    if (hasContent)
                    {
                        result.Add(current.ToString());
                        current.Clear();
                        hasContent = false;
                    }
                    break;
                default:
                    current.Append(c);
                    hasContent = true;
                    break;
            }
        }

        if (inDouble || inSingle)
        {
            throw new InvalidOperationException(
                $"ASPIRE_TERMINAL_HOST_INVOCATION_ARGS has unterminated {(inDouble ? "double" : "single")} quote.");
        }

        if (hasContent)
        {
            result.Add(current.ToString());
        }

        return [.. result];
    }
}

View on GitHub (pinned to 25830f84bd)