LykosAI/StabilityMatrix · error · UriFormatException

Uri has unsupported scheme. Uri

Error message

Uri has unsupported scheme. Uri:{source}

What it means

BetterAsyncImage.SetSource loads the image by inspecting the URI scheme: 'avares' is loaded via AssetLoader, and any other scheme (http, https, file, data) reaches an explicit UriFormatException('Uri has unsupported scheme'). This vendored async image control only supports Avalonia resource URIs in this code path.

Solutions

  1. Convert the image into an Avalonia resource and reference it as avares://<Assembly>/Assets/...
  2. Use a different control (e.g. the async image variant that supports http) for remote URLs
  3. Pre-download the image and embed it as a resource
  4. Validate the URI scheme before assigning Source

Example fix

// before
image.Source = new Uri("https://example.com/pic.png");
// after
image.Source = new Uri("avares://StabilityMatrix.Avalonia/Assets/pic.png");
Defensive patterns

Strategy: validation

Validate before calling

if (source is { } u && u.Scheme != "avares")
    throw new NotSupportedException($"BetterAsyncImage supports only avares URIs, got {u.Scheme}");

Type guard

bool IsResourceUri(Uri? u) => u?.Scheme == "avares";

Try / catch

try { image.Source = uri; }
catch (UriFormatException ex) { Log.Error(ex, "Unsupported URI scheme: {Uri}", uri); image.Source = fallbackBitmap; }

Prevention

When it happens

Trigger: Binding Source to an http://, https://, file:// or data: URI, or passing a malformed/empty URI whose scheme is neither 'avares' nor handled by earlier branches.

Common situations: Migrating from a normal Image/AsyncImage that accepted web URLs to BetterAsyncImage without converting assets to avares:// resources; a null/empty Source producing a default URI with no recognized scheme.

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

Appendix: source

Thrown at StabilityMatrix.Avalonia/Controls/VendorLabs/AsyncImage/BetterAsyncImage.cs:172

                    if (uri.Scheme == "file" && File.Exists(uri.LocalPath))
                    {
                        if (!IsCacheEnabled)
                        {
                            return decodeWidth > 0
                                ? SkiaExtensions.DecodeFileToAvaloniaImageScaled(uri.LocalPath, decodeWidth)
                                : new Bitmap(uri.LocalPath);
                        }

                        return await LoadImageAsync(uri, decodeWidth, newTokenSource.Token);
                    }

                    if (uri.Scheme == "avares")
                    {
                        return new Bitmap(AssetLoader.Open(uri));
                    }

                    throw new UriFormatException($"Uri has unsupported scheme. Uri:{source}");
                },
                CancellationToken.None
            );

            newTokenSource.Token.ThrowIfCancellationRequested();

            AttachSource(bitmap, newTokenSource.Token);
        }
        catch (OperationCanceledException ex)
        {
            State = AsyncImageState.Unloaded;

            // Logger.Info(ex, "Canceled loading image from {Uri}", uri);
        }
        catch (Exception ex)
        {
            State = AsyncImageState.Failed;

View on GitHub (pinned to af93d6ef57)