LykosAI/StabilityMatrix · error · ArgumentException

Uri scheme is not supported

Error message

Uri scheme is not supported

What it means

CacheBase.GetFromCacheOrDownloadAsync inspects uri.Scheme to decide between local file and web download paths; when the scheme matches neither supported branch it throws ArgumentException('Uri scheme is not supported', nameof(uri)). The cache layer only supports the URI schemes it explicitly handles.

Solutions

  1. Use http:// or https:// (or the supported local-path scheme) for cached downloads
  2. Handle avares:// resources separately via AssetLoader instead of the cache
  3. Validate Uri.TryCreate and the scheme before calling the cache
  4. Normalize the URI (add scheme) before caching

Example fix

// before
cache.GetFromCacheOrDownloadAsync(new Uri("avares://App/Assets/x.png"));
// after
var bmp = AssetLoader.Open(new Uri("avares://App/Assets/x.png"));
Defensive patterns

Strategy: validation

Validate before calling

if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps && !uri.IsFile)
    throw new ArgumentException($"Unsupported scheme {uri.Scheme} for cache", nameof(uri));

Type guard

bool IsCacheableUri(Uri u) => u.Scheme is "http" or "https" or "file";

Try / catch

try { await cache.GetFromCacheOrDownloadAsync(uri); }
catch (ArgumentException ex) { Log.Error(ex, "Unsupported scheme for {Uri}", uri); }

Prevention

When it happens

Trigger: Passing a URI with an unsupported scheme (e.g. avares://, ftp://, data:, or a relative path without scheme) to the image/file cache's request path.

Common situations: Feeding Avalonia resource URIs into a cache designed for http/local-file URIs; malformed URLs lacking a scheme; switching image sources from web to embedded resources without bypassing the cache.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix.Avalonia/Controls/VendorLabs/Cache/CacheBase.cs:552

                    if (instance != null)
                    {
                        break;
                    }
                }
                catch (FileNotFoundException) { }
            }

            // Cache
            if (instance != null && InMemoryFileStorage?.MaxItemCount > 0)
            {
                var msi = new InMemoryStorageItem<T>(fileName, DateTime.Now, instance);
                InMemoryFileStorage?.SetItem(msi);
            }
        }
        else
        {
            throw new ArgumentException("Uri scheme is not supported", nameof(uri));
        }

        return instance;
    }

    [DebuggerDisableUserUnhandledExceptions]
    private async Task<T?> DownloadFileAsync(
        Uri uri,
        string baseFile,
        bool preCacheOnly,
        CancellationToken cancellationToken
    )
    {
        var instance = default(T);

        Debug.WriteLine($"CacheBase Getting: {uri}");

        using var ms = new MemoryStream();

View on GitHub (pinned to af93d6ef57)