d2phap/ImageGlass · error · InvalidDataException

Unable to load '{themeFolderName}' theme pack. Please make s

Error message

Unable to load '{themeFolderName}' theme pack. Please make sure '{themeConfigPath}' file is valid.

What it means

Thrown by Config.FindAndLoadThemePack (v9) when, after trying the theme in the Config dir, then the Startup dir, then the built-in default theme, the loaded IgTheme still reports IsValid == false AND throwIfThemeInvalid is true. IsValid is driven by the theme config file (the IgTheme config JSON) being malformed or missing required fields. The exception names the theme folder and the expected config file path so the user can locate/repair it.

Source

Thrown at v9/Components/ImageGlass.Settings/Config.cs:1645

            // cannot find theme, use fall back theme
            if (!th.IsValid && useFallBackTheme)
            {
                th.Dispose();
                th = null;

                // load default theme
                th = new(App.StartUpDir(Dir.Themes, Const.DEFAULT_THEME));
            }
        }


        if (!th.IsValid && throwIfThemeInvalid)
        {
            th.Dispose();
            th = null;

            throw new InvalidDataException($"Unable to load '{themeFolderName}' theme pack. " +
                $"Please make sure '{themeConfigPath}' file is valid.");
        }

        return th;
    }


    /// <summary>
    /// Triggers <see cref="RequestUpdatingTheme"/> event.
    /// </summary>
    public static void TriggerRequestUpdatingTheme()
    {
        RequestUpdatingTheme?.Invoke(new RequestUpdatingThemeEventArgs(Config.Theme));
    }


    /// <summary>
    /// Triggers <see cref="RequestUpdatingLanguage"/> event.

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Open the named themeConfigPath and validate the JSON (syntax + required fields); fix or restore from a backup.
  2. If the active theme is unrecoverable, delete/empty the theme folder so FindAndLoadThemePack falls back to the default theme (set useFallBackTheme=true).
  3. Reinstall/repair ImageGlass to restore the default theme pack referenced by Const.DEFAULT_THEME.
  4. Call FindAndLoadThemePack with throwIfThemeInvalid=false to get a null instead of an exception and handle gracefully.

Example fix

// before
var theme = Config.FindAndLoadThemePack(name, useFallBackTheme: true, throwIfThemeInvalid: true);

// after: tolerate invalid, fall back to default
var theme = Config.FindAndLoadThemePack(name, useFallBackTheme: true, throwIfThemeInvalid: false)
           ?? new IgTheme(App.StartUpDir(Dir.Themes, Const.DEFAULT_THEME));
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the theme config JSON before loading.
var themeConfigPath = Path.Combine(themeFolder, "#config.json");
if (!File.Exists(themeConfigPath))
    throw new InvalidDataException($"Missing theme config: {themeConfigPath}");
try { JsonNode.Parse(File.ReadAllText(themeConfigPath)); }
catch (Exception) { throw new InvalidDataException($"Malformed theme config: {themeConfigPath}"); }

Try / catch

try { theme = Config.FindAndLoadThemePack(name, useFallBackTheme: true, throwIfThemeInvalid: true); }
catch (InvalidDataException ex)
{ theme = new IgTheme(App.StartUpDir(Dir.Themes, Const.DEFAULT_THEME)); Log.Warn(ex.Message); }

Prevention

When it happens

Trigger: The active theme's config JSON is corrupt, truncated, or missing required keys; the theme folder was partially deleted; a hand-edited theme has invalid JSON syntax; the default theme itself is damaged (e.g. a botched install).

Common situations: Editing a theme config and breaking JSON; an interrupted theme download; copying a theme folder but omitting the config file; an ImageGlass upgrade that changed the theme schema and left an old theme invalid.

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/1a4e926b2566d6b4. Report an issue: GitHub.