microsoft/aspire · error · ArgumentNullException

sourcePath

Error message

sourcePath

What it means

ConfigFileAnnotation throws ArgumentNullException when constructed with a null sourcePath. This internal annotation records the path of a custom config file to attach to a resource, and a null path would make the annotation meaningless.

Solutions

  1. Pass a non-empty, verified file path to the constructor.
  2. Resolve the path with an absolute base before construction and fail earlier with a clearer message if missing.
  3. Check the upstream path expression for null (e.g. Environment.GetEnvironmentVariable result) before creating the annotation.

Example fix

// before
var annotation = new ConfigFileAnnotation(Environment.GetEnvironmentVariable("MY_CONFIG"));

// after
var path = Environment.GetEnvironmentVariable("MY_CONFIG") ?? throw new InvalidOperationException("MY_CONFIG is not set.");
var annotation = new ConfigFileAnnotation(path);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(sourcePath)) throw new InvalidOperationException("Config file path must be a non-empty path.");

Type guard

if (sourcePath is not null) { new ConfigFileAnnotation(sourcePath); }

Prevention

When it happens

Trigger: Constructing ConfigFileAnnotation with a null string, typically from a helper that resolves a file path which failed to resolve.

Common situations: Path resolution helpers returning null when the config file does not exist or an environment variable used in the path is unset.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ServiceBus/ConfigFileAnnotation.cs:15

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

using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Azure.ServiceBus;

/// <summary>
/// Represents an annotation for a custom config file source.
/// </summary>
internal sealed class ConfigFileAnnotation : IResourceAnnotation
{
    public ConfigFileAnnotation(string sourcePath)
    {
        SourcePath = sourcePath ?? throw new ArgumentNullException(nameof(sourcePath));
    }

    public string SourcePath { get; }
}

View on GitHub (pinned to 25830f84bd)