LykosAI/StabilityMatrix · warning · ValidationException

Resources.Validation_ApiKeyRequired

Error message

Resources.Validation_ApiKeyRequired

What it means

The Gemini API key dialog in AccountSettingsViewModel validates input with ValidationException(Resources.Validation_ApiKeyRequired), thrown when the key is null or whitespace. The message text is the localized resource string named Validation_ApiKeyRequired, so the runtime message is the localized 'API key required' text rather than the literal resource name.

Solutions

  1. Obtain a Gemini API key from Google AI Studio and paste it into the field before confirming.
  2. Trim whitespace around the pasted key.
  3. If the message shows the raw resource name, refresh/repair the localized Resources files so Validation_ApiKeyRequired resolves.

Example fix

// before
throw new ValidationException(Resources.Validation_ApiKeyRequired);
// after
throw new ValidationException(string.IsNullOrWhiteSpace(Resources.Validation_ApiKeyRequired)
    ? "API key is required" : Resources.Validation_ApiKeyRequired);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(geminiKey)) {
    // get a key from Google AI Studio before opening the dialog
    return;
}

Type guard

bool HasGeminiKey(string? s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try { await ShowGeminiKeyDialog(); }
catch (ValidationException ex) { ShowStatus(ex.Message); }

Prevention

When it happens

Trigger: Submitting the 'Set Gemini API key' dialog (AccountSettingsViewModel.cs:652) with an empty or whitespace-only key.

Common situations: User has not obtained a Google AI Studio API key; paste failed or pasted only spaces; masked password field hides emptiness; missing/older resource assembly yields an unexpected message text.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs:652

    {
        HasGeminiApiKey = value.IsConnected;
    }

    [RelayCommand]
    private async Task SetGeminiApiKey()
    {
        if (!await BeforeConnectCheck())
            return;

        var field = new TextBoxField
        {
            Label = Resources.Label_GeminiApiKey,
            IsPassword = true,
            Validator = s =>
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    throw new ValidationException(Resources.Validation_ApiKeyRequired);
                }
            },
        };

        var dialog = DialogHelper.CreateTextEntryDialog(
            Resources.Label_SetGeminiApiKey,
            Resources.Text_SetGeminiApiKeyDescription,
            null,
            [field]
        );
        dialog.PrimaryButtonText = Resources.Action_Save;

        if (await dialog.ShowAsync() != ContentDialogResult.Primary || field.Text is not { } apiKey)
        {
            return;
        }

        await accountsService.GeminiLoginAsync(apiKey);

View on GitHub (pinned to af93d6ef57)