{"record":{"id":"d6866e08cc9fc343","repo":"microsoft/aspire","slug":"process-command-processcommandspec-executablepath","errorCode":null,"errorMessage":"Process command '{processCommandSpec.ExecutablePath}' environment variables require non-empty names.","messagePattern":"Process command '(.+?)' environment variables require non-empty names\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":3436,"sourceCode":"    }\n\n    private static ProcessSpec CreateProcessSpec(ExecuteCommandContext context, ProcessCommandSpec processCommandSpec, ProcessCommandOptions commandOptions)\n    {\n        var arguments = processCommandSpec.Arguments ?? [];\n        foreach (var argument in arguments)\n        {\n            if (argument is null)\n            {\n                throw new DistributedApplicationException($\"Process command '{processCommandSpec.ExecutablePath}' arguments cannot contain null values.\");\n            }\n        }\n\n        var environmentVariables = processCommandSpec.EnvironmentVariables ?? new Dictionary<string, string>();\n        foreach (var (name, value) in environmentVariables)\n        {\n            if (string.IsNullOrWhiteSpace(name))\n            {\n                throw new DistributedApplicationException($\"Process command '{processCommandSpec.ExecutablePath}' environment variables require non-empty names.\");\n            }\n\n            if (value is null)\n            {\n                throw new DistributedApplicationException($\"Process command '{processCommandSpec.ExecutablePath}' environment variable '{name}' requires a value.\");\n            }\n        }\n\n        return new ProcessSpec(processCommandSpec.ExecutablePath)\n        {\n            WorkingDirectory = processCommandSpec.WorkingDirectory,\n            ArgumentList = arguments,\n            EnvironmentVariables = environmentVariables,\n            InheritEnv = processCommandSpec.InheritEnvironmentVariables,\n            StandardInputContent = processCommandSpec.StandardInputContent,\n            KillEntireProcessTree = processCommandSpec.KillEntireProcessTree,\n            ThrowOnNonZeroReturnCode = false,\n            ResolveExecutablePath = true,","sourceCodeStart":3418,"sourceCodeEnd":3454,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3418-L3454","documentation":"In the same pre-launch validation pass, CreateProcessSpec rejects environment variable entries with blank names in the final ProcessCommandSpec, throwing a DistributedApplicationException that names the executable. Blank names cannot be set on an OS process environment.","triggerScenarios":"Return a ProcessCommandSpec from a C# processSpecFactory whose EnvironmentVariables dictionary contains an empty/whitespace key, then run the command (this check runs on the C# callback route as well as export routes).","commonSituations":"Dictionary keys built from string interpolation or parsed config where the name collapses to empty; reusing a dictionary shared with other APIs that tolerated blank keys; deserialization filling empty keys.","solutions":["Guarantee all keys in EnvironmentVariables are non-empty, non-whitespace strings.","Skip or rename blank keys when building the dictionary, failing loudly if the name is required.","Fix upstream parsing/interpolation that produces empty names."],"exampleFix":"// before\nenv[$\"{prefix}_TOKEN\"] = token; // prefix empty -> \"_TOKEN\"? no: \"\" when prefix null via interpolation of null\n// after\nif (!string.IsNullOrWhiteSpace(prefix))\n{\n    env[$\"{prefix}_TOKEN\"] = token;\n}","handlingStrategy":"validation","validationCode":"foreach (var k in processCommandSpec.EnvironmentVariables?.Keys ?? Enumerable.Empty<string>())\n    if (string.IsNullOrWhiteSpace(k)) throw new InvalidOperationException($\"Blank env name in spec for '{processCommandSpec.ExecutablePath}'.\");","typeGuard":"static bool EnvValid(ProcessCommandSpec? s) => s?.EnvironmentVariables is null || s.EnvironmentVariables.Keys.All(k => !string.IsNullOrWhiteSpace(k));","tryCatchPattern":"try { await command(); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"environment variables require non-empty names\"))\n{ logger.LogError(ex, \"Blank env var name in spec for {Exe}\", exePath); }","preventionTips":["Validate keys when building the dictionary, not at launch time","Avoid key interpolation with possibly-null prefixes","Cover command execution in tests to surface blank names early"],"tags":["process-command","environment-variables","empty-required-field"],"backgroundTag":"empty-required-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}