microsoft/aspire · error · ArgumentException

An absolute path is required

Error message

An absolute path is required: '${basePath}'

What it means

The AspireStore constructor requires basePath to be an absolute (rooted) filesystem path. Relative paths are rejected with ArgumentException because the store must be able to unambiguously locate and create its directory regardless of the current working directory.

Solutions

  1. Pass an absolute path, e.g. Path.GetFullPath(yourPath) or AppContext.BaseDirectory-combined path
  2. Use Environment.GetFolderPath / AppContext.BaseDirectory to anchor the store location before construction
  3. If accepting user input, validate with Path.IsPathRooted before calling the constructor

Example fix

// before
var store = new AspireStore(".aspire", directoryService);
// after
var store = new AspireStore(Path.GetFullPath(".aspire"), directoryService);
Defensive patterns

Strategy: validation

Validate before calling

if (!Path.IsPathRooted(basePath)) basePath = Path.GetFullPath(basePath);

Type guard

bool IsAbsolute(string? p) => !string.IsNullOrWhiteSpace(p) && Path.IsPathRooted(p);

Try / catch

try { var store = new AspireStore(basePath, svc); } catch (ArgumentException ex) when (ex.ParamName == "basePath") { basePath = Path.GetFullPath(basePath); /* retry */ }

Prevention

When it happens

Trigger: Constructing AspireStore (directly or via distributed application builder store APIs) with a relative path such as ".aspire" or "store" instead of a fully rooted path.

Common situations: Passing a user-supplied config directory without calling Path.GetFullPath; paths built from environment variables that may be relative; running from a different working directory than assumed.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/ApplicationModel/AspireStore.cs:31

    internal const string AspireStorePathKeyName = "Aspire:Store:Path";

    private readonly string _basePath;
    private readonly IFileSystemService _directoryService;

    /// <summary>
    /// Initializes a new instance of the <see cref="AspireStore"/> class with the specified base path.
    /// </summary>
    /// <param name="basePath">The base path for the store.</param>
    /// <param name="directoryService">The directory service for creating temp directories.</param>
    /// <returns>A new instance of <see cref="AspireStore"/>.</returns>
    public AspireStore(string basePath, IFileSystemService directoryService)
    {
        ArgumentNullException.ThrowIfNull(basePath);
        ArgumentNullException.ThrowIfNull(directoryService);

        if (!Path.IsPathRooted(basePath))
        {
            throw new ArgumentException($"An absolute path is required: '${basePath}'", nameof(basePath));
        }

        _basePath = basePath;
        _directoryService = directoryService;
        EnsureDirectory();
    }

    public string BasePath => _basePath;

    public string GetFileNameWithContent(string filenameTemplate, Stream contentStream)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(filenameTemplate);
        ArgumentNullException.ThrowIfNull(contentStream);

        EnsureDirectory();

        // Strip any folder information from the filename.
        filenameTemplate = Path.GetFileName(filenameTemplate);

View on GitHub (pinned to 25830f84bd)