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
- Null-check and existence-check the DirectoryInfo before calling.
- Build DirectoryInfo only from a validated non-empty path.
- 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
- Validate DirectoryInfo is non-null and Exists before launching.
- Construct DirectoryInfo only from validated non-empty paths.
- Handle folder-picker cancel (null) explicitly.
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
- Value cannot be null. (Parameter 'fileInfo')
- Duration value cannot be negative.
- DelayBetweenIterations value cannot be negative.
- IterationCount value cannot be larger than long.MaxValue.
- This cue object's value should be within or equal to 0.0 and
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/b678923865d56389.
Report an issue: GitHub.