{"record":{"id":"644e1b0769de0491","repo":"microsoft/aspire","slug":"process-command-arguments-cannot-contain-null-values","errorCode":null,"errorMessage":"Process command arguments cannot contain null values.","messagePattern":"Process command arguments cannot contain null values\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":3379,"sourceCode":"            StandardInputContent = exportOptions.StandardInputContent,\n            KillEntireProcessTree = exportOptions.KillEntireProcessTree\n        });\n    }\n\n    private static ProcessCommandSpec CreateProcessCommandSpec(ProcessCommandSpecExportData exportData)\n    {\n        var executablePath = exportData.ExecutablePath;\n        if (string.IsNullOrWhiteSpace(executablePath))\n        {\n            throw new DistributedApplicationException(\"Process command requires a non-empty executable path.\");\n        }\n\n        var arguments = exportData.Arguments ?? [];\n        foreach (var argument in arguments)\n        {\n            if (argument is null)\n            {\n                throw new DistributedApplicationException(\"Process command arguments cannot contain null values.\");\n            }\n        }\n\n        return new ProcessCommandSpec(executablePath)\n        {\n            WorkingDirectory = exportData.WorkingDirectory,\n            Arguments = arguments.ToArray(),\n            EnvironmentVariables = CreateEnvironmentVariables(exportData.EnvironmentVariables),\n            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)","sourceCodeStart":3361,"sourceCodeEnd":3397,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3361-L3397","documentation":"While converting exported ProcessCommandSpecExportData, CreateProcessCommandSpec walks the Arguments collection and rejects any null element with a DistributedApplicationException. Arguments become the process's ArgumentList, where null entries are not representable.","triggerScenarios":"Pass Arguments containing a null entry to withProcessCommand export options, or return export data whose Arguments list includes null (common when building lists conditionally in a polyglot host), then execute the command.","commonSituations":"Building argument arrays by concatenating optional values where a missing value contributes null instead of being filtered; deserialized JSON argument lists with explicit null items; placeholder entries intended to be replaced later.","solutions":["Remove null entries from Arguments before returning the spec (e.g. args.Where(a => a is not null)).","Build arguments by only appending values that are actually present.","Replace null placeholders with real values or omit the argument entirely."],"exampleFix":"// before\nArguments = [\"run\", optionalArg /* may be null */, \"--verbose\"]\n// after\nvar args = new List<string> { \"run\", \"--verbose\" };\nif (optionalArg is not null) { args.Insert(1, optionalArg); }\nArguments = args;","handlingStrategy":"validation","validationCode":"var bad = exportData.Arguments?.IndexOf(null) ?? -1;\nif (bad >= 0) throw new InvalidOperationException($\"Argument at index {bad} is null.\");","typeGuard":"static bool HasNoNullArgs(IEnumerable<string?>? args) => args?.All(a => a is not null) ?? true;","tryCatchPattern":"try { await command(); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"arguments cannot contain null\"))\n{ logger.LogError(ex, \"Filter nulls from process command arguments\"); }","preventionTips":["Use args.Where(a => a is not null) when building argument lists from optional values","Avoid null placeholders in collection expressions","Test each command's execution path in unit tests"],"tags":["process-command","argument-validation","null-element"],"backgroundTag":"invalid-argument-value","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"}