AvaloniaUI/Avalonia · error · ArgumentNullException

Value cannot be null. (Parameter 'directoryInfo')

Error message

Value cannot be null. (Parameter 'directoryInfo')

What it means

LauncherExtensions.LaunchDirectoryInfoAsync(directoryInfo) wraps a System.IO.DirectoryInfo into a BclStorageFolder and forwards to ILauncher.LaunchFileAsync. It throws ArgumentNullException(nameof(directoryInfo)) on a null DirectoryInfo as a fail-fast precondition. Mirrors LaunchFileInfoAsync for the folder case.

Source

Thrown at src/Avalonia.Base/Platform/Storage/ILauncher.cs:61

    public static Task<bool> LaunchFileInfoAsync(this ILauncher launcher, FileInfo fileInfo)
    {
        _ = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));
        if (!fileInfo.Exists)
        {
            return Task.FromResult(false);
        }

        return launcher.LaunchFileAsync(new BclStorageFile(fileInfo));
    }

    /// <summary>
    /// Starts the default app associated with the specified storage directory (folder).
    /// </summary>
    /// <param name="launcher">ILauncher instance.</param>
    /// <param name="directoryInfo">The directory.</param>
    public static Task<bool> LaunchDirectoryInfoAsync(this ILauncher launcher, DirectoryInfo directoryInfo)
    {
        _ = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo));
        if (!directoryInfo.Exists)
        {
            return Task.FromResult(false);
        }

        return launcher.LaunchFileAsync(new BclStorageFolder(directoryInfo));
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Null-check and existence-check the DirectoryInfo before calling.
  2. Build DirectoryInfo only from a validated non-empty path.
  3. Handle the null/cancel branch explicitly instead of forwarding.

Example fix

// before
await Launcher.LaunchDirectoryInfoAsync(dir); // dir may be null

// after
if (dir is null || !dir.Exists) return false;
return await Launcher.LaunchDirectoryInfoAsync(dir);
Defensive patterns

Strategy: validation

Validate before calling

if (directoryInfo is null || !directoryInfo.Exists) return false;
return await Launcher.LaunchDirectoryInfoAsync(directoryInfo);

Type guard

bool IsValid(DirectoryInfo? d) => d is not null && d.Exists;

Prevention

When it happens

Trigger: Calling Launcher.LaunchDirectoryInfoAsync(null), or passing a DirectoryInfo that is null because the directory lookup/config returned null.

Common situations: A DirectoryInfo built from a user-supplied or config-supplied path that was empty/null, or a cancel from a folder picker yielding null, forwarded without a guard.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/b678923865d56389. Report an issue: GitHub.