{"record":{"id":"a41c000f768be9e2","repo":"microsoft/aspire","slug":"array-params-contains-null-item-values-a41c00","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.Testing/DistributedApplicationTestingBuilder.cs","lineNumber":448,"sourceCode":"            // test and CI output, so withhold the live browser credential from each while keeping their endpoint\n            // lines. The ASPIRE_DASHBOARD-prefixed value is copied to the child process by DashboardEventHandlers.\n            // Tests get the credential through GetDashboardUrlAsync instead.\n            [\"AppHost:SuppressDashboardLoginUrlInStartupSummary\"] = \"true\",\n            [KnownConfigNames.DashboardSuppressBrowserTokenInOutput] = \"true\"\n        });\n    }\n\n    private static void ThrowIfNullOrContainsIsNullOrEmpty(string[] args)\n    {\n        ArgumentNullException.ThrowIfNull(args);\n        foreach (var arg in args)\n        {\n            if (string.IsNullOrEmpty(arg))\n            {\n                var values = string.Join(\", \", args);\n                if (arg is null)\n                {\n                    throw new ArgumentNullException(nameof(args), $\"Array params contains null item: [{values}]\");\n                }\n                throw new ArgumentException($\"Array params contains empty item: [{values}]\", nameof(args));\n            }\n        }\n    }\n\n    /// <summary>\n    /// The dashboard testing configuration resolved during builder construction. Carried as a single value so the\n    /// pre-construction and post-construction halves of the configuration cannot drift apart.\n    /// </summary>\n    private readonly record struct DashboardTestingState(bool Enabled, string? BrowserToken, string? ResourceServiceApiKey);\n\n    private sealed class SuspendingDistributedApplicationFactory(\n        Type entryPoint,\n        string[] args,\n        DistributedApplicationTestingBuilderOptions? testingOptions,\n        Action<DistributedApplicationOptions, HostApplicationBuilderSettings> configureBuilder)\n        : DistributedApplicationFactory(entryPoint, args)","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationTestingBuilder.cs#L430-L466","documentation":"ThrowIfNullOrContainsIsNullOrEmpty throws ArgumentNullException when the string[] args parameter passed to DistributedApplicationTestingBuilder.CreateAsync/Create contains a null element. The message lists all args to make the offending array easy to diagnose.","triggerScenarios":"Calling DistributedApplicationTestingBuilder.CreateAsync<T>(new string[] { null }) or passing an array built dynamically that contains a null entry (e.g. from a dictionary value or optional CLI argument that was null).","commonSituations":"Building args from config where a value is null; spreading a list with trailing nulls; passing (string[]?) variables without checking.","solutions":["Filter nulls before calling: args.Where(a => a is not null).ToArray()","Ensure every element is a non-empty string like \"--key=value\"","Validate args with the same null/empty check in test helper code"],"exampleFix":"// before\nawait DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(new[] { \"--feature\", null });\n// after\nvar args = new[] { \"--feature\", \"on\" }.Where(a => !string.IsNullOrEmpty(a)).ToArray();\nawait DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(args);","handlingStrategy":"validation","validationCode":"if (args.Any(a => a is null)) throw new InvalidOperationException(\"args contains null items\");","typeGuard":"static string[] WithoutNulls(string?[] args) => args.Where(a => a is not null).ToArray()!;","tryCatchPattern":"try { await DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(args); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"args\")\n{\n    // sanitize args and retry\n}","preventionTips":["Sanitize dynamically built argument arrays before passing","Never pass nullable string arrays directly","Prefer explicit \"--flag=value\" entries over positional nulls"],"tags":["aspire","testing","arguments","null"],"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"}