{"record":{"id":"a72006455bee795f","repo":"microsoft/aspire","slug":"argumentnullexception-for-parameter-args-args-is-null","errorCode":null,"errorMessage":"ArgumentNullException for parameter 'args' (args is null).","messagePattern":"ArgumentNullException for parameter 'args' \\(args is null\\)\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/CommandLineArgsCallbackAnnotation.cs","lineNumber":112,"sourceCode":"/// <param name=\"cancellationToken\"> The cancellation token associated with this execution.</param>\n[AspireExport]\npublic sealed class CommandLineArgsCallbackContext(IList<object> args, CancellationToken cancellationToken = default)\n{\n    private readonly IResource? _resource;\n\n    /// <summary>\n    /// Represents a callback context for the list of command-line arguments associated with an executable resource.\n    /// </summary>\n    /// <param name=\"args\"> The list of command-line arguments.</param>\n    /// <param name=\"resource\"> The resource associated with this callback context.</param>\n    /// <param name=\"cancellationToken\"> The cancellation token associated with this execution.</param>\n    public CommandLineArgsCallbackContext(IList<object> args, IResource resource, CancellationToken cancellationToken = default)\n        : this(args, cancellationToken) => _resource = resource ?? throw new ArgumentNullException(nameof(resource));\n\n    /// <summary>\n    /// Gets the list of command-line arguments.\n    /// </summary>\n    public IList<object> Args { get; } = args ?? throw new ArgumentNullException(nameof(args));\n\n    /// <summary>\n    /// Gets the cancellation token associated with the callback context.\n    /// </summary>\n    public CancellationToken CancellationToken { get; } = cancellationToken;\n\n    /// <summary>\n    /// Gets or sets the execution context for the distributed application.\n    /// </summary>\n    public DistributedApplicationExecutionContext ExecutionContext { get; init; } = new(DistributedApplicationOperation.Run);\n\n    /// <summary>\n    /// Gets or sets the logger for the distributed application.\n    /// </summary>\n    public ILogger Logger { get; init; } = NullLogger.Instance;\n\n    /// <summary>\n    /// Gets the editor used to manipulate command-line arguments in polyglot callbacks.","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/CommandLineArgsCallbackAnnotation.cs#L94-L130","documentation":"Primary constructor null guard in CommandLineArgsCallbackContext: the 'args' list argument is null. The context wraps the caller's argument list to mutate it in place, so a null list has nothing to wrap and every subsequent editor operation would fail.","triggerScenarios":"new CommandLineArgsCallbackContext(null, resource) or the 2-arg overload with a null IList<object>.","commonSituations":"Manually constructing the context in tests or custom pipelines with an uninitialized args list; a method returning null args passed straight through.","solutions":["Pass a concrete list, e.g. new List<object>() or resource annotations' args list","Initialize the args collection before constructing the context"],"exampleFix":"// before\nvar ctx = new CommandLineArgsCallbackContext(null, resource);\n// after\nvar ctx = new CommandLineArgsCallbackContext(new List<object>(), resource);","handlingStrategy":"validation","validationCode":"var argsList = args ?? new List<object>();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize args lists with new List<object>() before constructing contexts","Never pass possibly-null collections into context constructors"],"tags":["null-argument","callback-context"],"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"}