AvaloniaUI/Avalonia · error · ArgumentNullException

Value cannot be null. (Parameter 'fileInfo')

Error message

Value cannot be null. (Parameter 'fileInfo')

What it means

LauncherExtensions.LaunchFileInfoAsync(fileInfo) is a convenience extension over ILauncher.LaunchFileAsync that wraps a System.IO.FileInfo into a BclStorageFile. It throws ArgumentNullException(nameof(fileInfo)) when fileInfo is null, before any platform call. This is a standard fail-fast precondition on the public extension surface.

Source

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

    Task<bool> LaunchFileAsync(IStorageItem storageItem);
}

internal class NoopLauncher : ILauncher
{
    public Task<bool> LaunchUriAsync(Uri uri) => Task.FromResult(false); 
    public Task<bool> LaunchFileAsync(IStorageItem storageItem) => Task.FromResult(false);
} 

public static class LauncherExtensions
{
    /// <summary>
    /// Starts the default app associated with the specified storage file.
    /// </summary>
    /// <param name="launcher">ILauncher instance.</param>
    /// <param name="fileInfo">The file.</param>
    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)
        {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Null-check the FileInfo before calling, and return/handle 'nothing to launch' when null.
  2. Construct the FileInfo from a validated, non-empty path and verify fileInfo.Exists before forwarding.
  3. Where the source can legitimately be null on cancel, branch the logic instead of forwarding.

Example fix

// before
await Launcher.LaunchFileInfoAsync(file); // file may be null

// after
if (file is null) return false;
if (!file.Exists) return false;
return await Launcher.LaunchFileInfoAsync(file);
Defensive patterns

Strategy: validation

Validate before calling

if (fileInfo is null || !fileInfo.Exists) return false;
return await Launcher.LaunchFileInfoAsync(fileInfo);

Type guard

bool IsValid(FileInfo? f) => f is not null && f.Exists;

Prevention

When it happens

Trigger: Calling Launcher.LaunchFileInfoAsync(null) directly, or passing a FileInfo variable that is null because the producing code (e.g. a path lookup, a dialog result) returned null.

Common situations: A FileInfo obtained from a nullable source (DirectoryInfo.GetFiles filtering, a picker that returns null on cancel, a config path that was never set) is forwarded to LaunchFileInfoAsync without a null check.

Related errors


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