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 CommandLineArgsEditor: the 'args' list passed to the editor is null. The editor mutates the shared argument list in place (ATS-first editing for polyglot callbacks), so a null list cannot be adapted to.

Solutions

  1. Pass the CommandLineArgsCallbackContext's Args list (or a valid IList<object>) to the editor
  2. Initialize an empty List<object> if no arguments exist yet

Example fix

// before
var editor = new CommandLineArgsEditor(null);
// after
var editor = new CommandLineArgsEditor(context.Args);
Defensive patterns

Strategy: validation

Validate before calling

if (args is null) args = new List<object>();

Prevention

When it happens

Trigger: Constructing CommandLineArgsEditor(null), e.g. from exported callback tooling where the context's Args list was null or not passed through.

Common situations: Polyglot (non-C#) callback hosts wiring the editor without the args collection; custom pipelines constructing the editor before args exist.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/e2f29b1bbacafbf4. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/ApplicationModel/CommandLineArgsEditor.cs:12

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// Provides an ATS-first editor for command-line arguments within polyglot callbacks.
/// </summary>
[AspireExport]
internal sealed class CommandLineArgsEditor(IList<object> args)
{
    private readonly IList<object> _args = args ?? throw new ArgumentNullException(nameof(args));

    /// <summary>
    /// Adds a command-line argument.
    /// </summary>
    /// <param name="value">The argument to add.</param>
    [AspireExport]
    public void Add(
        [AspireUnion(
            typeof(string),
            typeof(ReferenceExpression),
            typeof(EndpointReference),
            typeof(IResourceBuilder<ParameterResource>),
            typeof(IResourceBuilder<IResourceWithConnectionString>),
            typeof(IExpressionValue))]
        object value)
    {
        ArgumentNullException.ThrowIfNull(value);
        _args.Add(value);

View on GitHub (pinned to 25830f84bd)