LykosAI/StabilityMatrix · error · ApplicationException

Failed to parse parameters

Error message

Failed to parse parameters

What it means

LoadImageMetadata in InferenceTabViewModelBase reads a dropped/opened image's metadata and calls GenerationParameters.TryParse on the 'Parameters' (SMProject-style) JSON payload. When the stored parameters string cannot be deserialized into a GenerationParameters object, it throws this ApplicationException. This is a deliberate hard failure because continuing with partial inference settings would corrupt the restored tab state.

Solutions

  1. Regenerate or re-export the image from Stability Matrix so the Parameters metadata is written by the current version
  2. Inspect the image's embedded metadata and fix the Parameters JSON so it matches the current GenerationParameters schema
  3. Upgrade Stability Matrix if the image came from a newer version that changed the schema
  4. Catch the ApplicationException in the Drop/AddTabFromFileAsync path and fall back to opening the image without parameters

Example fix

// before
if (!GenerationParameters.TryParse(metadata.Parameters, out var parameters))
    throw new ApplicationException("Failed to parse parameters");

// after
if (!GenerationParameters.TryParse(metadata.Parameters, out var parameters))
{
    Logger.Warn("Could not parse Parameters metadata; loading image without parameters");
    return; // or load defaults instead of throwing
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Before calling LoadImageMetadata
var meta = ImageMetadata.TryExtract(filePath);
if (meta?.Parameters is not null &&
    !GenerationParameters.TryParse(meta.Parameters, out _))
{
    Logger.Warn("Image has unparseable Parameters metadata; will load without parameters");
}

Type guard

bool HasParsableParameters(ImageMetadata m) =>
    m.Parameters is null || GenerationParameters.TryParse(m.Parameters, out _);

Try / catch

try
{
    tabVm.LoadImageMetadata(sender, filePath);
}
catch (ApplicationException ex) when (ex.Message == "Failed to parse parameters")
{
    Logger.Warn(ex, "Parameter metadata unreadable; opening image without parameters");
    tabVm.OpenImageWithoutParameters(filePath);
}

Prevention

When it happens

Trigger: Calling LoadImageMetadata (via Drop or AddTabFromFileAsync) on an image whose metadata 'Parameters' field is present but not valid GenerationParameters JSON — e.g. parameters written by a newer/older Stability Matrix version, hand-edited EXIF/PNG chunks, or metadata copied from another tool.

Common situations: Dragging an inference image generated by a different Stability Matrix version whose GenerationParameters schema has changed; images edited in external tools that mangled the embedded parameter JSON; manually copying parameters between images with wrong quoting.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix.Avalonia/ViewModels/Base/InferenceTabViewModelBase.cs:261

                if (this is IImageGalleryComponent imageGalleryComponent)
                {
                    Dispatcher.UIThread.Invoke(() =>
                        imageGalleryComponent.LoadImagesToGallery(new ImageSource(imageFilePath))
                    );
                }

                return;
            }
        }

        // Has generic metadata
        if (metadata.Parameters is not null)
        {
            Logger.Info("Loading Parameters from metadata");

            if (!GenerationParameters.TryParse(metadata.Parameters, out var parameters))
            {
                throw new ApplicationException("Failed to parse parameters");
            }

            if (this is IParametersLoadableState paramsLoadableVm)
            {
                Dispatcher.UIThread.Invoke(() => paramsLoadableVm.LoadStateFromParameters(parameters));
            }
            else
            {
                Logger.Warn(
                    "Load parameters target {Type} does not implement IParametersLoadableState, skipping",
                    GetType().Name
                );
            }

            // Load image
            if (this is IImageGalleryComponent imageGalleryComponent)
            {
                Dispatcher.UIThread.Invoke(() =>

View on GitHub (pinned to af93d6ef57)