microsoft/aspire · error · ArgumentNullException
ArgumentNullException for parameter 'args' (args is null).
Error message
ArgumentNullException for parameter 'args' (args is null).
What it means
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.
Solutions
- Pass a concrete list, e.g. new List<object>() or resource annotations' args list
- Initialize the args collection before constructing the context
Example fix
// before var ctx = new CommandLineArgsCallbackContext(null, resource); // after var ctx = new CommandLineArgsCallbackContext(new List<object>(), resource);
Defensive patterns
Strategy: validation
Validate before calling
var argsList = args ?? new List<object>();
Prevention
- Initialize args lists with new List<object>() before constructing contexts
- Never pass possibly-null collections into context constructors
When it happens
Trigger: new CommandLineArgsCallbackContext(null, resource) or the 2-arg overload with a null IList<object>.
Common situations: Manually constructing the context in tests or custom pipelines with an uninitialized args list; a method returning null args passed straight through.
Related errors
- ArgumentNullException for parameter 'resource' (resource is…
- adminPassword
- ArgumentNullException for parameter 'args' (args is null).
- ArgumentNullException for parameter 'callback' (callback is…
- ArgumentNullException for parameter 'path' (PathString…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/a72006455bee795f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ApplicationModel/CommandLineArgsCallbackAnnotation.cs:112
/// <param name="cancellationToken"> The cancellation token associated with this execution.</param>
[AspireExport]
public sealed class CommandLineArgsCallbackContext(IList<object> args, CancellationToken cancellationToken = default)
{
private readonly IResource? _resource;
/// <summary>
/// Represents a callback context for the list of command-line arguments associated with an executable resource.
/// </summary>
/// <param name="args"> The list of command-line arguments.</param>
/// <param name="resource"> The resource associated with this callback context.</param>
/// <param name="cancellationToken"> The cancellation token associated with this execution.</param>
public CommandLineArgsCallbackContext(IList<object> args, IResource resource, CancellationToken cancellationToken = default)
: this(args, cancellationToken) => _resource = resource ?? throw new ArgumentNullException(nameof(resource));
/// <summary>
/// Gets the list of command-line arguments.
/// </summary>
public IList<object> Args { get; } = args ?? throw new ArgumentNullException(nameof(args));
/// <summary>
/// Gets the cancellation token associated with the callback context.
/// </summary>
public CancellationToken CancellationToken { get; } = cancellationToken;
/// <summary>
/// Gets or sets the execution context for the distributed application.
/// </summary>
public DistributedApplicationExecutionContext ExecutionContext { get; init; } = new(DistributedApplicationOperation.Run);
/// <summary>
/// Gets or sets the logger for the distributed application.
/// </summary>
public ILogger Logger { get; init; } = NullLogger.Instance;
/// <summary>
/// Gets the editor used to manipulate command-line arguments in polyglot callbacks.View on GitHub (pinned to 25830f84bd)