{"record":{"id":"0ada56e5e4acd8f9","repo":"microsoft/aspire","slug":"process-command-processcommandspec-executablepath-arguments","errorCode":null,"errorMessage":"Process command '{processCommandSpec.ExecutablePath}' 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":3427,"sourceCode":"            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        {\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)","sourceCodeStart":3409,"sourceCodeEnd":3445,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3409-L3445","documentation":"CreateProcessSpec performs a second validation pass on the final ProcessCommandSpec just before launching the process. It rejects any null element in Arguments with a DistributedApplicationException that includes the executable path, because ArgumentList passed to the OS cannot contain nulls.","triggerScenarios":"Return a ProcessCommandSpec from a C# processSpecFactory whose Arguments list contains a null entry, then invoke the command; this triggers even though the earlier export-path check (error 1885) only runs on the export route.","commonSituations":"C# factories building argument lists conditionally where nulls slip in; spreading optional values with collection expressions; passing values read from configuration that deserialize to null.","solutions":["Filter nulls out of Arguments before constructing the spec (args.Where(a => a is not null).ToArray()).","Append arguments only when their source value is non-null.","Assert/validate your factory output in tests covering command execution."],"exampleFix":"// before\nArguments = [\"publish\", outputPath, \"--force\"] // outputPath may be null\n// after\nvar args = new List<string> { \"publish\", \"--force\" };\nif (outputPath is not null) { args.Insert(1, outputPath); }\nArguments = args;","handlingStrategy":"validation","validationCode":"var bad = processCommandSpec.Arguments?.IndexOf(null) ?? -1;\nif (bad >= 0) throw new InvalidOperationException($\"Spec for '{processCommandSpec.ExecutablePath}' has null argument at {bad}.\");","typeGuard":"static bool ArgsValid(ProcessCommandSpec? s) => s is null || s.Arguments?.All(a => a is not null) != false;","tryCatchPattern":"try { await command(); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"arguments cannot contain null\"))\n{ logger.LogError(ex, \"Null argument in spec for {Exe}\", exePath); }","preventionTips":["Filter nulls in C# factories exactly as in export callbacks","Append arguments conditionally instead of interpolating nulls","Snapshot-test spec factories with representative context data"],"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"}