{"record":{"id":"1f34cffd96881a9a","repo":"microsoft/aspire","slug":"array-params-contains-empty-item-values-1f34cf","errorCode":null,"errorMessage":"Array params contains empty item: [{values}]","messagePattern":"Array params contains empty item: \\[(.+?)\\]","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Testing/DistributedApplicationTestingBuilder.cs","lineNumber":450,"sourceCode":"            // 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)\n    {\n        private readonly SemaphoreSlim _continueBuilding = new(0);","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationTestingBuilder.cs#L432-L468","documentation":"ThrowIfNullOrContainsIsNullOrEmpty throws ArgumentException when the string[] args parameter to DistributedApplicationTestingBuilder.CreateAsync/Create contains an empty string element. Empty entries would be forwarded as meaningless arguments to the app host, so they are rejected with a message listing the full args array.","triggerScenarios":"Calling DistributedApplicationTestingBuilder.CreateAsync<T>(new[] { \"\" }) or passing arrays assembled from empty config values / split strings that produced empty entries (e.g. \"\" .Split(',') on an empty env var).","commonSituations":"Reading CLI args from an empty environment variable and splitting; concatenating optional flags where missing values yield \"\"; copy-pasted test setup with leftover empty strings.","solutions":["Filter empty strings: args.Where(a => !string.IsNullOrEmpty(a)).ToArray()","Guard env-var-derived args for empty input before splitting","Only pass well-formed \"--name=value\" style arguments"],"exampleFix":"// before\nvar extra = Environment.GetEnvironmentVariable(\"EXTRA_ARGS\")?.Split(' ') ?? []; // may contain \"\"\nawait DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(extra);\n// after\nvar extra = (Environment.GetEnvironmentVariable(\"EXTRA_ARGS\") ?? \"\")\n    .Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\nawait DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(extra);","handlingStrategy":"validation","validationCode":"if (args.Any(string.IsNullOrEmpty)) throw new InvalidOperationException(\"args contains empty items\");","typeGuard":"static string[] NonEmptyArgs(IEnumerable<string?> source) =>\n    source.Where(a => !string.IsNullOrEmpty(a)).ToArray()!;","tryCatchPattern":"try { await DistributedApplicationTestingBuilder.CreateAsync<Projects.AppHost>(args); }\ncatch (ArgumentException ex) when (ex.ParamName == \"args\")\n{\n    // filter empty entries and retry\n}","preventionTips":["Use RemoveEmptyEntries when splitting strings into args","Guard env-var-sourced arguments for empty values","Keep helper methods that build args returning sanitized arrays"],"tags":["aspire","testing","arguments","validation"],"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-21T04:17:39.646Z"}