iOfficeAI/OfficeCLI · error · ArgumentException

Invalid display value '{value}'. Expected 'icon' or 'content

Error message

Invalid display value '{value}'. Expected 'icon' or 'content'.

What it means

Thrown by NormalizeOleDisplay when the 'display' property is a non-null string that is not 'icon' or 'content' (case-insensitive, after trim). Ambiguous synonyms like 'embed', 'invisible', numbers, or boolean strings are intentionally rejected so the user is told their input was wrong instead of silently falling back. The original (un-trimmed, original-case) value is echoed in the message.

Source

Thrown at src/officecli/Core/OleHelper.cs:528

    /// <summary>
    /// Normalize and validate the caller-supplied <c>display</c> property
    /// for an OLE object. Canonical values are <c>"icon"</c> (show the file
    /// as a clickable icon preview) and <c>"content"</c> (show the embedded
    /// file's first page as a live picture). Any other value — including
    /// ambiguous synonyms like <c>"embed"</c>, <c>"invisible"</c>, numbers,
    /// or boolean strings — is rejected with <see cref="ArgumentException"/>
    /// so the user is told their input was wrong instead of silently
    /// falling back to "icon". Used by Word/PPT Add and Set.
    /// </summary>
    public static string NormalizeOleDisplay(string value)
    {
        if (value == null)
            throw new ArgumentException(
                "Invalid display value ''. Expected 'icon' or 'content'.");
        var v = value.Trim().ToLowerInvariant();
        if (v == "icon") return "icon";
        if (v == "content") return "content";
        throw new ArgumentException(
            $"Invalid display value '{value}'. Expected 'icon' or 'content'.");
    }

    /// <summary>
    /// Known OLE Add/Set property keys shared across Word/PPT/Excel. Used by
    /// <see cref="WarnOnUnknownOleProps"/> to surface silently-ignored
    /// properties via stderr. Kept as a single union so the three handlers
    /// stay consistent — per-handler differences (e.g. Excel's "anchor"
    /// range string) are all represented here.
    /// </summary>
    private static readonly HashSet<string> KnownOleProps = new(StringComparer.OrdinalIgnoreCase)
    {
        "src", "path", "progId", "progid",
        "width", "height", "x", "y",
        "icon", "preview", "display", "name",
        "anchor",
        // dump→batch round-trip carrier keys: when src is a data: URI the
        // payload bytes are already in final embedded form, so oleKind +

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use exactly 'icon' or 'content' (case-insensitive).
  2. Map your synonym to a canonical value before the call: display = (d == "embed") ? "content" : d.
  3. Check the handler's docstring / KnownOleProps for the accepted vocabulary.

Example fix

// before
props["display"] = "embed"; // throws 281
AddOle(props);

// after
props["display"] = "content"; // canonical token
AddOle(props);
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> ValidDisplays = new(StringComparer.OrdinalIgnoreCase) { "icon", "content" };
if (!ValidDisplays.Contains(props.GetValueOrDefault("display") ?? ""))
    props["display"] = "icon";

Type guard

static bool IsValidDisplay(string? v)
    => v != null && (v.Trim().Equals("icon", StringComparison.OrdinalIgnoreCase)
                  || v.Trim().Equals("content", StringComparison.OrdinalIgnoreCase));

Try / catch

try { display = NormalizeOleDisplay(raw); }
catch (ArgumentException ex) when (ex.Message.Contains("display value"))
{ display = "icon"; Console.Error.WriteLine($"unknown display '{raw}', defaulted to icon"); }

Prevention

When it happens

Trigger: Passing display="embed", display="1", display="true", display="thumbnail", or any value that is a reasonable synonym but not one of the two canonical tokens. Also triggered by typos like 'contnt'.

Common situations: Copying display vocabulary from a different OOXML tool (e.g. one that uses 'embed'/'linked'); passing a numeric flag from a shell script; locale-specific spelling assumptions.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/025a0a0cc127b43d. Report an issue: GitHub.