AvaloniaUI/Avalonia · error · IOException

Unable to select a suitable storage provider

Error message

Unable to select a suitable storage provider

What it means

FallbackStorageProvider.GetFor(filter) enumerates the available IStorageProvider instances via GetProviders() and returns the first that satisfies the filter (e.g. CanOpen, CanSave, CanPickFolder). If the enumeration yields no match it throws IOException 'Unable to select a suitable storage provider'. This is the fallback aggregator used when the platform lacks a native picker.

Source

Thrown at src/Avalonia.Base/Platform/Storage/FallbackStorageProvider.cs:53

            yield return p;
        for (;_nextProviderFactory < _factories.Length;)
        {
            var p = await _factories[_nextProviderFactory]();
            _nextProviderFactory++;
            if (p != null)
            {
                _providers.Add(p);
                yield return p;
            }
        }
    }
    
    async Task<IStorageProvider> GetFor(Func<IStorageProvider, bool> filter)
    {
        await foreach (var p in GetProviders())
            if (filter(p))
                return p;
        throw new IOException("Unable to select a suitable storage provider");
    }
    

    // Those should _really_ have been asynchronous,
    // but this class is expected to fall back to the managed implementation anyway
    public bool CanOpen => true;
    public bool CanSave => true;
    public bool CanPickFolder => true;
    
    public async Task<IReadOnlyList<IStorageFile>> OpenFilePickerAsync(FilePickerOpenOptions options)
    {
        return await (await GetFor(p => p.CanOpen)).OpenFilePickerAsync(options);
    }

    public async Task<OpenFilePickerResult> OpenFilePickerWithResultAsync(FilePickerOpenOptions options)
    {
        return await (await GetFor(p => p.CanOpen)).OpenFilePickerWithResultAsync(options);
    }

View on GitHub (pinned to 11c5427268)

Solutions

  1. Register at least one IStorageProvider that supports the needed capability with the fallback provider before invoking the picker.
  2. Guard the call: read StorageProvider.CanOpen/CanSave/CanPickFolder and skip the picker when false, showing a 'not supported' message instead.
  3. On desktop platforms, ensure the windowing subsystem (e.g. Win32/X11/macOS backend) is initialized so its native storage provider is attached.
  4. In tests/headless scenarios, inject a mock IStorageProvider that reports the required capability as true.

Example fix

// before: call picker directly in an unsupported environment
var files = await StorageProvider.OpenFilePickerAsync(opts); // throws

// after: guard capability and/or register a provider
if (!StorageProvider.CanOpen) return;
var files = await StorageProvider.OpenFilePickerAsync(opts);
Defensive patterns

Strategy: validation

Validate before calling

if (!StorageProvider.CanOpen) { ShowNotSupported(); return; }
var files = await StorageProvider.OpenFilePickerAsync(opts);

Type guard

bool CanPick(IStorageProvider p, Func<IStorageProvider,bool> need) => need(p);

Try / catch

try { await StorageProvider.OpenFilePickerAsync(opts); }
catch (IOException) { /* no provider: degrade to manual path entry */ }

Prevention

When it happens

Trigger: Calling OpenFilePickerAsync/SaveFilePickerAsync/FindFilePickerAsync on the fallback provider when every registered/injected provider reports the relevant capability (CanOpen/CanSave/CanPickFolder) as false, or no providers are registered at all.

Common situations: Running in a headless/server environment with no windowing backend, forgetting to attach the platform storage provider on a custom host, an integration test driving the fallback provider with no providers added, or a platform backend that incorrectly reports all capabilities as false.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/df1217d48d031eda. Report an issue: GitHub.