LykosAI/StabilityMatrix · error · FileNotFoundException

Image file does not exist

Error message

Image file does not exist

What it means

GetHashGuidFileNameCached() builds a content-hash-based GUID file name for the image. When the ImageSource wraps a local file, the code asserts the file exists before hashing; if LocalFile.Exists is false it throws FileNotFoundException with the missing path. The library requires an existing, readable file because the hash is computed from the file's bytes.

Solutions

  1. Check LocalFile.Exists (or File.Exists on the path) before calling GetHashGuidFileNameCached and skip or refresh the ImageSource if false.
  2. Re-create the ImageSource from a path that currently exists on disk.
  3. If the file is produced asynchronously, await its completion before hashing.
  4. Wrap the call in try/catch for FileNotFoundException and fall back to a placeholder or re-scan.

Example fix

// before
var name = imageSource.GetHashGuidFileNameCached();
// after
if (imageSource.LocalFile is { Exists: true })
{
    var name = imageSource.GetHashGuidFileNameCached();
}
else
{
    // regenerate, rescan, or skip this image
}
Defensive patterns

Strategy: validation

Validate before calling

if (imageSource.LocalFile is { } f && !f.Exists)
{
    throw new FileNotFoundException($"Image missing before hashing: {f.FullName}");
}

Type guard

bool Hashable(ImageSource s) => s.LocalFile is { Exists: true } || s.Bitmap is not null;

Try / catch

try { var name = img.GetHashGuidFileNameCached(); }
catch (FileNotFoundException ex) { log.Warn($"Image vanished: {ex.FileName}"); SkipOrRefresh(img); }

Prevention

When it happens

Trigger: Calling GetHashGuidFileNameCached() on an ImageSource constructed with a LocalFile whose path no longer exists (file deleted, moved, or path constructed before the file was written).

Common situations: Image was deleted or renamed between acquisition and hashing; referencing an output image from a previous generation that was cleaned up; path built from stale metadata; running on a different machine/drive where the relative path is invalid.

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/48d20159705d1061. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/Models/ImageSource.cs:233

        return guid;
    }

    /// <summary>
    /// Return a file name with Guid from Blake3 hash
    /// This will throw if the Blake3 hash has not been calculated yet
    /// </summary>
    public string GetHashGuidFileNameCached()
    {
        // Calculate hash if not available
        if (contentHashBlake3 is null)
        {
            // Local file
            if (LocalFile is not null)
            {
                // File must exist
                if (!LocalFile.Exists)
                {
                    throw new FileNotFoundException("Image file does not exist", LocalFile);
                }

                // Fail in debug since hash should have been pre-calculated
                Debug.Fail("Hash has not been calculated when GetHashGuidFileNameCached() was called");

                var data = LocalFile.ReadAllBytes();
                contentHashBlake3 = FileHash.GetBlake3Parallel(data);
            }
            // Bitmap
            else if (Bitmap is not null)
            {
                var data = Bitmap.ToByteArray();
                contentHashBlake3 = FileHash.GetBlake3Parallel(data);
            }
            else
            {
                throw new InvalidOperationException("ImageSource is not a local file or bitmap");
            }

View on GitHub (pinned to af93d6ef57)