LykosAI/StabilityMatrix · error · InvalidOperationException

Definition ' ' has InitialValue of ' ', but it was not…

Error message

Definition '{definition.Name}' has InitialValue of '{definition.InitialValue}', but it was not found in options: '{string.Join(",", definition.Options)}'

What it means

Initialize validates that a definition's saved InitialValue actually matches one of its declared Options for single/multiple select types. If the persisted value is not present in the option list (FirstOrDefault returns null), the dialog cannot represent the stored choice and throws with the definition name, value, and option list.

Solutions

  1. Update the saved launch option value to one that exists in the definition's Options list.
  2. Update or reinstall the package so the definition's Options include the saved value (or reset its InitialValue).
  3. Check for case/whitespace mismatches between the stored value and the option strings.
  4. Clear the stale setting for that option to fall back to the definition default.

Example fix

// before (saved value missing from new options)
"initialValue": "fast", "options": ["turbo", "safe"]
// after
"initialValue": "turbo", "options": ["turbo", "safe"]
Defensive patterns

Strategy: validation

Validate before calling

if (d.InitialValue is string v && !d.Options.Contains(v))
    d.InitialValue = d.Options.FirstOrDefault() ?? throw new InvalidOperationException($"{d.Name}: InitialValue '{v}' not in options");

Type guard

static bool InitialValueInOptions(LaunchOptionDefinition d) =>
    d.InitialValue is null || d.Options.Any(o => o.Equals(d.InitialValue));

Try / catch

try { viewModel.Initialize(definitions); }
catch (InvalidOperationException ex) when (ex.Message.Contains("was not found in options"))
{
    logger.Warning(ex, "Stale InitialValue; resetting to default");
    // reset the saved value and re-initialize
}

Prevention

When it happens

Trigger: Opening the launch options dialog when a definition's InitialValue (from saved settings or package defaults) is not string-equal to any entry in definition.Options.

Common situations: Package updated its option list (renamed or removed choices) while the user's saved InitialValue still holds the old value; case/whitespace differences between the saved value and the options; hand-edited settings file referencing a nonexistent option.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix/ViewModels/LaunchOptionsDialogViewModel.cs:105

            }
            // Store initial values
            if (definition.InitialValue != null)
            {
                // For bool types, initial value can be string (single/multiple options) or bool (single option)
                if (definition.Type == LaunchOptionType.Bool)
                {
                    // For single option, check bool
                    if (definition.Options.Count == 1 && definition.InitialValue is bool boolValue)
                    {
                        initialOptions[definition.Options.First()] = boolValue;
                    }
                    else
                    {
                        // For single/multiple options (string only)
                        var option = definition.Options.FirstOrDefault(opt => opt.Equals(definition.InitialValue));
                        if (option == null)
                        {
                            throw new InvalidOperationException(
                                $"Definition '{definition.Name}' has InitialValue of '{definition.InitialValue}', but it was not found in options:" +
                                $" '{string.Join(",", definition.Options)}'");
                        }
                        initialOptions[option] = true;
                    }
                }
                else
                {
                    // Otherwise store initial value for first option
                    initialOptions[definition.Options.First()] = definition.InitialValue;
                }
            }
            Cards.Add(new LaunchOptionCard(definition));
        }
        // Load launch args
        var launchArgsDict = launchArgs.ToDictionary(launchArg => launchArg.Name);
        foreach (var card in Cards)
        {

View on GitHub (pinned to af93d6ef57)