d2phap/ImageGlass · error · ArgumentException

' ' is not a valid loading order. ---------- 👉🏼 Method…

Error message

'{orderByStr}' is not a valid loading order.

----------
👉🏼 Method: IG_SetLoadingOrderBy

What it means

Thrown by the string overload of IG_SetLoadingOrderBy when Enum.TryParse<ImageOrderBy>(orderByStr) fails. ImageOrderBy is case-insensitively parsed; valid members are Name, Random, FileSize, Extension, DateCreated, DateAccessed, DateModified, ExifDateTaken, ExifRating. These names are also language keywords and must not be renamed.

Solutions

  1. Use one of the exact enum names: Name, Random, FileSize, Extension, DateCreated, DateAccessed, DateModified, ExifDateTaken, ExifRating.
  2. Validate with Enum.TryParse<ImageOrderBy> upstream and call the typed overload.
  3. Trim whitespace and map common aliases ('date' -> DateModified) before calling.

Example fix

// before
api.IG_SetLoadingOrderBy(userInput);

// after
if (Enum.TryParse<ImageOrderBy>(userInput?.Trim(), true, out var orderBy))
{
    api.IG_SetLoadingOrderBy(orderBy);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.TryParse<ImageOrderBy>(orderByStr?.Trim(), true, out var orderBy))
    throw new ArgumentException($"Unknown order '{orderByStr}'.");
api.IG_SetLoadingOrderBy(orderBy);

Type guard

static bool IsValidOrderBy(string? s) => Enum.TryParse<ImageOrderBy>(s?.Trim(), true, out _);

Try / catch

try { api.IG_SetLoadingOrderBy(orderByStr); }
catch (ArgumentException ex) when (ex.ParamName == nameof(orderByStr))
{ /* valid: Name, Random, FileSize, Extension, DateCreated, DateAccessed, DateModified, ExifDateTaken, ExifRating */ }

Prevention

When it happens

Trigger: Calling IG_SetLoadingOrderBy(string) with a value not in the enum: 'date' (ambiguous; use DateModified/DateCreated/ExifDateTaken), 'size' (use FileSize), 'rating' (use ExifRating), 'filename' (use Name).

Common situations: Config file with a shortened alias; v9 setting name carried over; user-typed value in a custom command; trailing whitespace.

Related errors


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

Appendix: source

Thrown at source/ImageGlass.Lib/Common/ServiceProviders/AppAPIs/AppAPIProvider.cs:1531

    /// Sets whether to use the Explorer sort order.
    /// </summary>
    public static void IG_ToggleExplorerSortOrder(bool? enabled)
    {
        enabled ??= !Core.Config.EnableExplorerSortOrder;
        Core.Config.EnableExplorerSortOrder = enabled.Value;

        IG_ReloadList();
    }


    /// <summary>
    /// Sets the image loading order value.
    /// </summary>
    public void IG_SetLoadingOrderBy(string? orderByStr)
    {
        if (!Enum.TryParse<ImageOrderBy>(orderByStr, out var orderBy))
        {
            throw new ArgumentException($"""
                '{orderByStr}' is not a valid loading order.

                ----------
                👉🏼 Method: {nameof(IG_SetLoadingOrderBy)}
                """,
                nameof(orderByStr));
        }

        IG_SetLoadingOrderBy(orderBy);
    }


    /// <summary>
    /// Sets the image loading order value.
    /// </summary>
    public static void IG_SetLoadingOrderBy(ImageOrderBy orderBy)
    {
        if (orderBy == Core.Config.ImageLoadingOrder) return;

View on GitHub (pinned to 4a3c4fecef)