{"record":{"id":"155129a349080b08","repo":"microsoft/aspire","slug":"array-params-contains-null-item-values","errorCode":null,"errorMessage":"Array params contains null item: [{values}]","messagePattern":"Array params contains null item: \\[(.+?)\\]","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs","lineNumber":743,"sourceCode":"                stage.Entrypoint([\"python\", \"-m\", entrypoint]);\n                break;\n            case EntrypointType.Executable:\n                stage.Entrypoint([entrypoint]);\n                break;\n        }\n    }\n\n    private static void ThrowIfNullOrContainsIsNullOrEmpty(string[] scriptArgs)\n    {\n        ArgumentNullException.ThrowIfNull(scriptArgs);\n        foreach (var scriptArg in scriptArgs)\n        {\n            if (string.IsNullOrEmpty(scriptArg))\n            {\n                var values = string.Join(\", \", scriptArgs);\n                if (scriptArg is null)\n                {\n                    throw new ArgumentNullException(nameof(scriptArgs), $\"Array params contains null item: [{values}]\");\n                }\n                throw new ArgumentException($\"Array params contains empty item: [{values}]\", nameof(scriptArgs));\n            }\n        }\n    }\n\n    /// <summary>\n    /// Resolves the default virtual environment path by checking multiple candidate locations.\n    /// </summary>\n    /// <param name=\"builder\">The distributed application builder.</param>\n    /// <param name=\"appDirectory\">The Python app directory (relative to AppHost).</param>\n    /// <param name=\"virtualEnvironmentPath\">The relative virtual environment path (e.g., \".venv\").</param>\n    /// <returns>The resolved virtual environment path.</returns>\n    private static string ResolveDefaultVirtualEnvironmentPath(IDistributedApplicationBuilder builder, string appDirectory, string virtualEnvironmentPath)\n    {\n        var appDirectoryFullPath = Path.GetFullPath(appDirectory, builder.AppHostDirectory);\n\n        // Walk up from the Python app directory looking for the virtual environment","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs#L725-L761","documentation":"AddPythonApp validates its scriptArgs collection via ThrowIfNullOrContainsIsNullOrEmpty. If any element of scriptArgs is a null reference, it throws ArgumentNullException naming scriptArgs and including the full argument list in the message.","triggerScenarios":"Passing an array containing a null element to AddPythonApp, e.g. args built dynamically where one entry was never assigned: new[] { \"--flag\", null }.","commonSituations":"Dynamically assembled argument arrays from config or environment lookups returning null; conditional argument building that appends null instead of skipping.","solutions":["Inspect the args array passed to AddPythonApp and remove/skip null entries.","Add a filter before building: args = candidateArgs.Where(a => a is not null).ToArray().","Use ArgumentNullException.ThrowIfNull on individual computed arguments before adding them.","Read the list shown in the message ([values]) to find the null position."],"exampleFix":"// before\nbuilder.AddPythonApp(\"py\", \"main.py\", \"--flag\", null, \"other\");\n// after\nbuilder.AddPythonApp(\"py\", \"main.py\", \"--flag\", \"other\");","handlingStrategy":"validation","validationCode":"if (args.Any(a => a is null))\n    throw new InvalidOperationException(\"scriptArgs contains a null entry.\");","typeGuard":"static bool HasNullArg(string?[] args) => args.Any(a => a is null);","tryCatchPattern":"try\n{\n    builder.AddPythonApp(\"py\", \"main.py\", args);\n}\ncatch (ArgumentNullException ex)\n{\n    logger.LogError(ex, \"Null entry in python args: {Args}\", ex.Message);\n}","preventionTips":["Filter arrays with Where(a => a is not null) before passing script args.","Validate config-driven arguments before building the args array.","Avoid appending results of possibly-null lookups directly into arg collections."],"tags":["csharp","aspire","python","null-argument"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}