{"record":{"id":"5c0e1263547889c3","repo":"AvaloniaUI/Avalonia","slug":"value-cannot-be-null-parameter-fileinfo","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'fileInfo')","messagePattern":"Value cannot be null\\. \\(Parameter 'fileInfo'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Platform/Storage/ILauncher.cs","lineNumber":45,"sourceCode":"    Task<bool> LaunchFileAsync(IStorageItem storageItem);\n}\n\ninternal class NoopLauncher : ILauncher\n{\n    public Task<bool> LaunchUriAsync(Uri uri) => Task.FromResult(false); \n    public Task<bool> LaunchFileAsync(IStorageItem storageItem) => Task.FromResult(false);\n} \n\npublic static class LauncherExtensions\n{\n    /// <summary>\n    /// Starts the default app associated with the specified storage file.\n    /// </summary>\n    /// <param name=\"launcher\">ILauncher instance.</param>\n    /// <param name=\"fileInfo\">The file.</param>\n    public static Task<bool> LaunchFileInfoAsync(this ILauncher launcher, FileInfo fileInfo)\n    {\n        _ = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));\n        if (!fileInfo.Exists)\n        {\n            return Task.FromResult(false);\n        }\n\n        return launcher.LaunchFileAsync(new BclStorageFile(fileInfo));\n    }\n\n    /// <summary>\n    /// Starts the default app associated with the specified storage directory (folder).\n    /// </summary>\n    /// <param name=\"launcher\">ILauncher instance.</param>\n    /// <param name=\"directoryInfo\">The directory.</param>\n    public static Task<bool> LaunchDirectoryInfoAsync(this ILauncher launcher, DirectoryInfo directoryInfo)\n    {\n        _ = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo));\n        if (!directoryInfo.Exists)\n        {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Platform/Storage/ILauncher.cs#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Null-check the FileInfo before calling, and return/handle 'nothing to launch' when null.","Construct the FileInfo from a validated, non-empty path and verify fileInfo.Exists before forwarding.","Where the source can legitimately be null on cancel, branch the logic instead of forwarding."],"exampleFix":"// before\nawait Launcher.LaunchFileInfoAsync(file); // file may be null\n\n// after\nif (file is null) return false;\nif (!file.Exists) return false;\nreturn await Launcher.LaunchFileInfoAsync(file);","handlingStrategy":"validation","validationCode":"if (fileInfo is null || !fileInfo.Exists) return false;\nreturn await Launcher.LaunchFileInfoAsync(fileInfo);","typeGuard":"bool IsValid(FileInfo? f) => f is not null && f.Exists;","tryCatchPattern":null,"preventionTips":["Validate FileInfo is non-null and Exists before forwarding to the launcher.","Treat picker 'cancel' as null and branch instead of forwarding.","Centralize file-launch calls behind a helper that does the guard."],"tags":["avalonia","launcher","argumentnull","file-info","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}