LykosAI/StabilityMatrix · error · InvalidOperationException

Provider not found

Error message

Provider {providerId} not found

What it means

After confirming the conversation exists, SendMessageAsync resolves the image-generation provider by its string id via GetProvider. If no registered provider matches providerId, an InvalidOperationException is thrown. Providers are the registered backends (e.g. cloud API providers); the id must match one the service knows about.

Solutions

  1. Print/list the available providers and use an exact registered ProviderId (check GetProviders/provider registration in the service).
  2. Update stale provider ids in settings/conversation records after upgrading the app.
  3. Ensure provider registration (DI/startup) succeeded — a failed registration makes all ids unresolvable.
  4. Guard with a lookup: resolve the provider id against the available provider list before calling SendMessageAsync.

Example fix

// before
await chatService.SendMessageAsync(convId, "gemini-pro", prompt); // wrong id
// after
var providers = chatService.GetProviders();
var providerId = providers.FirstOrDefault(p => p.Id.Contains("gemini"))?.Id
    ?? throw new InvalidOperationException("No gemini provider registered");
await chatService.SendMessageAsync(convId, providerId, prompt);
Defensive patterns

Strategy: validation

Validate before calling

var knownProviders = chatService.GetProviders(); // or the registration list
string providerId = /* configured id */;
if (!knownProviders.Any(p => string.Equals(p.Id, providerId, StringComparison.OrdinalIgnoreCase)))
{
    throw new InvalidOperationException($"Unknown provider '{providerId}'. Available: {string.Join(", ", knownProviders.Select(p => p.Id))}");
}

Type guard

bool IsRegisteredProvider(string id, IEnumerable<ImageGenerationProvider> providers) =>
    providers.Any(p => string.Equals(p.Id, id, StringComparison.OrdinalIgnoreCase));

Try / catch

try
{
    await chatService.SendMessageAsync(conversationId, providerId, prompt);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Provider "))
{
    logger.LogError(ex, "Provider '{ProviderId}' not registered", providerId);
    providerId = chatService.GetProviders().First().Id; // fall back to first registered provider
    await chatService.SendMessageAsync(conversationId, providerId, prompt);
}

Prevention

When it happens

Trigger: Calling SendMessageAsync with a providerId string that does not match any registered provider — misspelled id, provider from a different app version, provider removed/unregistered at startup, or an id read from a conversation record saved by an older build.

Common situations: Config or persisted settings referencing a provider that was renamed between versions; passing a raw provider name string instead of the canonical ProviderId; provider registration failed silently at startup; tests using made-up provider ids.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix.Core/Services/ImageGeneration/ImageGenerationChatService.cs:431

        Guid conversationId,
        string providerId,
        string? textPrompt,
        List<string>? imagePaths,
        Dictionary<string, object>? providerOptions,
        IProgress<ImageGenerationProgress>? progress,
        CancellationToken cancellationToken = default
    )
    {
        var conversation = await GetConversationAsync(conversationId).ConfigureAwait(false);
        if (conversation == null)
        {
            throw new InvalidOperationException($"Conversation {conversationId} not found");
        }

        var provider = GetProvider(providerId);
        if (provider == null)
        {
            throw new InvalidOperationException($"Provider {providerId} not found");
        }

        // Update conversation's provider if it changed
        var providerChanged = conversation.ProviderId != providerId;
        if (providerChanged)
        {
            logger.LogInformation(
                "Switching conversation {ConversationId} provider from {OldProvider} to {NewProvider}",
                conversationId,
                conversation.ProviderId,
                providerId
            );
            conversation.ProviderId = providerId;
        }

        // Check for provider compatibility - thought signature requirements
        // If switching to a thinking model with incompatible history, we'll carry forward
        // the last output image as an input instead of using the full history

View on GitHub (pinned to af93d6ef57)