microsoft/aspire · error · DirectoryNotFoundException
Bundle version directory
Error message
Bundle version directory '{fullVersionDirectory}' does not exist. What it means
BundleVersionLease.Acquire coordinates exclusive access to a bundle version directory via file leases. Before acquiring, it validates that the version directory exists on disk; if not it throws DirectoryNotFoundException with the fully resolved path, preventing lease files from being created in a nonexistent location.
Solutions
- Ensure the version directory exists before acquiring: Directory.CreateDirectory(versionDirectory)
- Re-check where the path in the environment variable came from; recreate the bundle version
- Re-run the bundle installation so the version directory is created
- Verify the path is not relative to an unexpected working directory — pass an absolute path
Example fix
// before BundleVersionLease.Acquire(versionDir, holderKind: "cli"); // after Directory.CreateDirectory(versionDir); BundleVersionLease.Acquire(versionDir, holderKind: "cli");
Defensive patterns
Strategy: try-catch
Validate before calling
var full = Path.GetFullPath(versionDirectory); if (!Directory.Exists(full)) Directory.CreateDirectory(full);
Try / catch
try { lease = BundleVersionLease.Acquire(versionDir, holderKind); }
catch (DirectoryNotFoundException)
{ /* recreate the version directory and retry once */ } Prevention
- Create the version directory as part of bundle installation, before leasing
- Pass absolute paths; don't rely on the current working directory
- Clean up env-var pointers when temp directories are purged
When it happens
Trigger: Calling Acquire (directly or via TryAcquireFromEnvironment when the env var points at a path) with a versionDirectory that was deleted, never created, or mounted after the call.
Common situations: Stale environment variable pointing at a cleaned temp directory; bundle upgraded/removed by another process between validation and acquisition; wrong path passed on the CLI.
Related errors
- Browser user data directory
- Could not replace Aspire skills cache directory
- Directory ' ' contains no pom.xml, build.gradle…
- Failed to acquire file lock
- Multiple NuGet.config files found in
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/41de9c1cb65ad550.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/BundleVersionLease.cs:101
public string? CommandName { get; }
/// <summary>
/// Gets when the lease was acquired.
/// </summary>
public DateTimeOffset AcquiredUtc { get; }
/// <summary>
/// Creates a lease for <paramref name="versionDirectory"/>.
/// </summary>
public static BundleVersionLease Acquire(string versionDirectory, string holderKind, string? commandName = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(versionDirectory);
ArgumentException.ThrowIfNullOrWhiteSpace(holderKind);
var fullVersionDirectory = Path.GetFullPath(versionDirectory);
if (!Directory.Exists(fullVersionDirectory))
{
throw new DirectoryNotFoundException($"Bundle version directory '{fullVersionDirectory}' does not exist.");
}
var leasesDirectory = Path.Combine(fullVersionDirectory, LeasesDirectoryName);
Directory.CreateDirectory(leasesDirectory);
var heldLease = HeldFileLease.Acquire(leasesDirectory, CreateLeaseFileNamePrefix(), LeaseExtension);
try
{
var versionId = Path.GetFileName(fullVersionDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
var lease = new BundleVersionLease(
versionId,
fullVersionDirectory,
heldLease.LeasePath,
Environment.ProcessId,
GetCurrentProcessStartTimeTicks(),
holderKind,
commandName,View on GitHub (pinned to 25830f84bd)