{"record":{"id":"8fca832ca42736e1","repo":"microsoft/aspire","slug":"array-params-contains-null-item-values-8fca83","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/DistributedApplicationFactory.cs","lineNumber":161,"sourceCode":"    /// <summary>\n    /// Called when the application has been built.\n    /// </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,","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs#L143-L179","documentation":"DistributedApplicationFactory validates the args array passed to its constructor before starting the app host. A null element inside the args array is treated as a programming error, so it throws ArgumentNullException naming the args parameter and listing all values.","triggerScenarios":"Calling new DistributedApplicationFactory<TEntryPoint>(args) (directly or via a factory base class) with an array such as new string[] { null } or an array containing a null element, e.g. from string.Split results or uninitialized entries.","commonSituations":"Building args dynamically from configuration or environment parsing where a missing value yields null; passing the result of string.Split with missing segments; test setup code assembling CLI args programmatically.","solutions":["Filter out null entries before constructing the factory: args.Where(a => a is not null).ToArray()","Fix the code producing the args array so nulls never enter it (default missing values to empty string or omit them)","Add a guard/assertion in test setup that validates all args are non-null","If a null signals a missing required setting, resolve that setting explicitly and fail with a clear message"],"exampleFix":"// before\nvar args = new string[] { \"--DcpPublisher:LifeCycle=false\", null };\nvar factory = new DistributedApplicationFactory<Program>(args);\n// after\nvar args = new[] { \"--DcpPublisher:LifeCycle=false\" }.Where(a => !string.IsNullOrEmpty(a)).ToArray();\nvar factory = new DistributedApplicationFactory<Program>(args);","handlingStrategy":"validation","validationCode":"static string[] ValidateArgs(string?[] args) =>\n    args.All(a => a is not null)\n        ? args!.\n        : throw new ArgumentException(\"args contains null entries\", nameof(args));","typeGuard":"static bool HasNoNulls(string?[] args) => Array.TrueForAll(args, a => a is not null);","tryCatchPattern":"try\n{\n    var factory = new DistributedApplicationFactory<Program>(args);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"args\")\n{\n    throw new InvalidOperationException(\"Test args must not contain null entries\", ex);\n}","preventionTips":["Build args with collection expressions and string literals, never nullable placeholders","Use string.Split with RemoveEmptyEntries when deriving args from strings","Sanitize config-derived values: skip null/empty instead of passing them through","Assert on composed args arrays in test setup helpers"],"tags":["args","null","testing","argument-validation"],"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"}