LykosAI/StabilityMatrix · error · IOException

File ( ) was not found

Error message

File {normalizedPath} ({filePath}) was not found

What it means

ClipboardExtensions.SetFileDataObjectAsync builds a file list for the system clipboard (DataObject file drop). For each supplied path it normalizes 'file:///' and 'file://' prefixes and asks the StorageProvider to resolve it; if the file does not exist on disk (TryGetFileFromPathAsync returns null), it throws IOException naming both the normalized and original path.

Solutions

  1. Verify File.Exists / TryGetFileFromPathAsync on each path before calling SetFileDataObjectAsync and filter out missing files.
  2. Convert relative paths to absolute, and pre-decode 'file://' URIs before passing them in.
  3. Catch the IOException and surface a 'file not found' message instead of letting it bubble.
  4. If running sandboxed, grant access or copy the file into app-accessible storage first.

Example fix

// before
await clipboard.SetFileDataObjectAsync(paths);

// after
var existing = paths.Where(p => File.Exists(p.StripStart("file:///").StripStart("file://"))).ToList();
if (existing.Count > 0)
    await clipboard.SetFileDataObjectAsync(existing);
Defensive patterns

Strategy: validation

Validate before calling

var ok = paths.All(p => File.Exists(p.StripStart("file:///").StripStart("file://")));

Try / catch

try
{
    await clipboard.SetFileDataObjectAsync(paths);
}
catch (IOException ex)
{
    notifier.ShowError($"Cannot copy to clipboard: {ex.Message}");
}

Prevention

When it happens

Trigger: Calling SetFileDataObjectAsync with a path to a file that was deleted or moved before the call, a relative path that is not resolvable by the StorageProvider, a malformed/percent-encoded URI string, or a path outside the app's accessible storage scopes.

Common situations: Drag-and-drop handlers caching a file path whose temp file was later cleaned up; passing URLs from a web view whose target file was never downloaded; sandboxed (flatpak/macos) apps receiving paths they cannot access.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/b9c5954ec0a9e0c3. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/Extensions/ClipboardExtensions.cs:40

    }

    /// <summary>
    /// Set file paths to the clipboard.
    /// </summary>
    /// <exception cref="IOException">Thrown if unable to get file from path</exception>
    public static async Task SetFileDataObjectAsync(this IClipboard clipboard, IEnumerable<string> filePaths)
    {
        var files = new List<IStorageFile>();

        foreach (var filePath in filePaths)
        {
            // Normalize path that might have come from avalonia storage provider already
            var normalizedPath = filePath.StripStart("file:///").StripStart("file://");

            var file = await StorageProvider.TryGetFileFromPathAsync(normalizedPath);
            if (file is null)
            {
                throw new IOException($"File {normalizedPath} ({filePath}) was not found");
            }

            files.Add(file);
        }

        if (files.Count == 0)
        {
            return;
        }

        var dataObject = new DataObject();
        dataObject.Set(DataFormats.Files, files);

        await clipboard.SetDataObjectAsync(dataObject);
    }
}

View on GitHub (pinned to af93d6ef57)