microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'iconName')

Error message

Value cannot be null. (Parameter 'iconName')

What it means

Primary constructor null guard in ResourceIconAnnotation: the 'iconName' string is null. iconName is a non-nullable positional parameter, so the runtime ArgumentNullException fires before the annotation is created; iconVariant has a default and is never the faulting input.

Solutions

  1. Pass a valid FluentUI system icon name (see https://aka.ms/fluentui-system-icons)
  2. Guard nulls before constructing the annotation and skip or substitute a default icon
  3. Fix the config source so a real icon name is provided

Example fix

// before
new ResourceIconAnnotation(iconName, IconVariant.Regular); // iconName is null
// after
new ResourceIconAnnotation(iconName ?? "Database", IconVariant.Regular);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(iconName)) iconName = "Database"; // FluentUI default

Try / catch

try { var ann = new ResourceIconAnnotation(iconName, variant); }
catch (ArgumentNullException) { /* supply a default icon name */ }

Prevention

When it happens

Trigger: Constructing new ResourceIconAnnotation(iconName: null, ...) directly or from a .WithIcon-style helper passing a null icon name.

Common situations: Reading an icon name from config or a constant that resolves to null; conditional icon assignment where a variable is uninitialized.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/ApplicationModel/ResourceIconAnnotation.cs:23

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// Specifies the icon to use when displaying a resource in the dashboard.
/// </summary>
/// <param name="iconName">The name of the FluentUI icon to use.</param>
/// <param name="iconVariant">The variant of the icon (Regular or Filled).</param>
[DebuggerDisplay("Type = {GetType().Name,nq}, IconName = {IconName}, IconVariant = {IconVariant}")]
public sealed class ResourceIconAnnotation(string iconName, IconVariant iconVariant = IconVariant.Filled) : IResourceAnnotation
{
    /// <summary>
    /// Gets the name of the FluentUI icon to use for the resource.
    /// </summary>
    /// <remarks>
    /// The icon name should be a valid FluentUI icon name. 
    /// See https://aka.ms/fluentui-system-icons for available icons.
    /// </remarks>
    public string IconName { get; } = iconName ?? throw new ArgumentNullException(nameof(iconName));

    /// <summary>
    /// Gets the variant of the icon (Regular or Filled).
    /// </summary>
    public IconVariant IconVariant { get; } = iconVariant;
}

View on GitHub (pinned to 25830f84bd)