{"record":{"id":"f99d0786776633ae","repo":"microsoft/aspire","slug":"array-params-contains-empty-item-values-f99d07","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/DistributedApplicationFactory.cs","lineNumber":163,"sourceCode":"    /// </summary>\n    /// <param name=\"application\">The application.</param>\n    protected virtual void OnBuilt(DistributedApplication application)\n    {\n    }\n\n    private static string[] 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        return args;\n    }\n\n    private void OnBuiltCore(DistributedApplication application)\n    {\n        _shutdownTimeout = application.Services.GetService<IOptions<HostOptions>>()?.Value.ShutdownTimeout ?? _shutdownTimeout;\n        _appTcs.TrySetResult(application);\n        OnBuilt(application);\n    }\n\n    private static void PreConfigureBuilderOptions(\n        DistributedApplicationOptions applicationOptions,\n        HostApplicationBuilderSettings hostBuilderOptions,\n        string[] args,\n        Assembly entryPointAssembly)\n    {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L145-L181","documentation":"DistributedApplicationFactory validates the args array passed to its constructor: an element that is the empty string is rejected with ArgumentException naming the args parameter and listing all values. Empty CLI arguments would be forwarded to the host builder and cause ambiguous parsing, so they are treated as invalid input.","triggerScenarios":"Calling new DistributedApplicationFactory<TEntryPoint>(args) with an array containing \"\" — commonly produced by string.Split on missing segments, Join/Split round-trips, or trimming entries that leave empty strings.","commonSituations":"args.Split(' ') on an input with double spaces; env-var or config-derived arguments that are empty; test code templating args where a placeholder resolved to nothing.","solutions":["Filter empty entries before constructing the factory: args.Where(a => !string.IsNullOrEmpty(a)).ToArray()","Fix the upstream Split/Join logic (use RemoveEmptyEntries: StringSplitOptions.RemoveEmptyEntries)","Default missing optional values to a meaningful argument or omit the argument entirely","Validate the composed args in test setup before passing them to the factory"],"exampleFix":"// before\nvar args = input.Split(' ');\nvar factory = new DistributedApplicationFactory<Program>(args);\n// after\nvar args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);\nvar factory = new DistributedApplicationFactory<Program>(args);","handlingStrategy":"validation","validationCode":"static string[] ValidateArgs(string[] args) =>\n    args.All(a => !string.IsNullOrEmpty(a))\n        ? args\n        : throw new ArgumentException(\"args contains empty entries\", nameof(args));","typeGuard":"static bool HasNoEmpty(string?[] args) => Array.TrueForAll(args, a => !string.IsNullOrEmpty(a));","tryCatchPattern":"try\n{\n    var factory = new DistributedApplicationFactory<Program>(args);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"args\")\n{\n    throw new InvalidOperationException(\"Test args must not contain empty strings\", ex);\n}","preventionTips":["Always use StringSplitOptions.RemoveEmptyEntries when splitting input into args","Template CLI args with defaults so placeholders never resolve to \"\"","Filter with Where(a => !string.IsNullOrEmpty(a)) in shared test factory helpers","Review args composition whenever configuration keys feeding them change"],"tags":["args","empty-string","testing","argument-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"}