{"record":{"id":"43dd18aca5005bf3","repo":"microsoft/aspire","slug":"process-command-environment-variables-require-non-empty","errorCode":null,"errorMessage":"Process command 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":3406,"sourceCode":"            InheritEnvironmentVariables = exportData.InheritEnvironmentVariables ?? true,\n            StandardInputContent = exportData.StandardInputContent,\n            KillEntireProcessTree = exportData.KillEntireProcessTree ?? true\n        };\n    }\n\n    private static Dictionary<string, string> CreateEnvironmentVariables(IReadOnlyDictionary<string, string>? environmentVariables)\n    {\n        var result = new Dictionary<string, string>(StringComparer.Ordinal);\n        if (environmentVariables is null)\n        {\n            return result;\n        }\n\n        foreach (var (name, value) in environmentVariables)\n        {\n            if (string.IsNullOrWhiteSpace(name))\n            {\n                throw new DistributedApplicationException(\"Process command environment variables require non-empty names.\");\n            }\n\n            if (value is null)\n            {\n                throw new DistributedApplicationException($\"Process command environment variable '{name}' requires a value.\");\n            }\n\n            result.Add(name, value);\n        }\n\n        return result;\n    }\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        {","sourceCodeStart":3388,"sourceCodeEnd":3424,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3388-L3424","documentation":"CreateEnvironmentVariables validates the EnvironmentVariables dictionary of exported process-command data. An environment variable name that is null, empty, or whitespace cannot be passed to the OS process, so a DistributedApplicationException is thrown.","triggerScenarios":"Provide EnvironmentVariables with a blank key ('', ' ', or null after deserialization) in withProcessCommand export options or in ProcessCommandSpecExportData returned by createProcessSpec, then run the command.","commonSituations":"Building a dictionary from parsed config lines where the name portion is empty; JSON objects deserialized with empty keys; string interpolation bugs producing keys that collapse to empty.","solutions":["Ensure every key in EnvironmentVariables is a non-empty, non-whitespace string.","Validate/sanitize names before adding them (skip or throw on blank keys at construction time).","If names come from parsing, fix the parser to reject or repair empty name segments."],"exampleFix":"// before\nenv[line.Split('=')[0]] = line.Split('=')[1]; // name can be empty for '=value'\n// after\nvar parts = line.Split('=', 2);\nif (!string.IsNullOrWhiteSpace(parts[0]))\n{\n    env[parts[0]] = parts[1];\n}","handlingStrategy":"validation","validationCode":"foreach (var k in exportData.EnvironmentVariables?.Keys ?? Enumerable.Empty<string>())\n    if (string.IsNullOrWhiteSpace(k)) throw new InvalidOperationException(\"Blank env var name in process command options.\");","typeGuard":"static bool EnvNamesValid(IDictionary<string, string>? env) => env is null || env.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, \"A blank environment variable name was supplied\"); }","preventionTips":["Sanitize parsed config keys before adding to env dictionaries","Reject empty keys at dictionary construction time","Log env var names (not values) during setup to spot blanks 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"}