{"record":{"id":"482208af429c097b","repo":"iOfficeAI/OfficeCLI","slug":"invalid-array-constant-badelem-inline-arrays","errorCode":null,"errorMessage":"Invalid array constant: '{badElem}'. Inline arrays {...} may contain only literal values (numbers, \"text\", TRUE/FALSE, errors) — not functions, cell references, or nested arrays. Reference a cell range instead (e.g. A1:A3).","messagePattern":"Invalid array constant: '(.+?)'\\. Inline arrays (.+?) may contain only literal values \\(numbers, \"text\", TRUE/FALSE, errors\\) — not functions, cell references, or nested arrays\\. Reference a cell range instead \\(e\\.g\\. A1:A3\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Formula/ModernFunctionQualifier.cs","lineNumber":300,"sourceCode":"\n    /// <summary>\n    /// Returns the formula with Excel 2016+ modern function names qualified\n    /// with <c>_xlfn.</c> / <c>_xlfn._xlws.</c> as required by OOXML. Leaves\n    /// already-qualified names, older functions, quoted string literals, and\n    /// non-function identifiers untouched.\n    /// </summary>\n    public static string Qualify(string formula)\n    {\n        if (string.IsNullOrEmpty(formula)) return formula;\n\n        // Excel inline array constants {…} may hold only literal values.\n        // A function call, cell reference, name, or nested array inside {…} makes\n        // Excel report the whole workbook as corrupt (it prompts to repair on\n        // open). Reject such a formula at write time so officecli never emits a\n        // file Excel refuses to open.\n        var badElem = FindNonLiteralArrayConstant(formula);\n        if (badElem != null)\n            throw new ArgumentException(\n                $\"Invalid array constant: '{badElem}'. Inline arrays {{...}} may contain only literal \" +\n                \"values (numbers, \\\"text\\\", TRUE/FALSE, errors) — not functions, cell references, or \" +\n                \"nested arrays. Reference a cell range instead (e.g. A1:A3).\");\n\n        // LET / LAMBDA parameter names are stored in the _xlpm. namespace; without\n        // that prefix Excel reports the workbook as corrupt. Collect every such\n        // name up front so all of its occurrences (declaration and uses) get the\n        // prefix below.\n        var lambdaParams = CollectLambdaParams(formula);\n\n        // Walk the string and only rewrite identifiers outside quoted strings.\n        // Excel formula strings are bounded by '\"' with '\"\"' as an escape.\n        var sb = new System.Text.StringBuilder(formula.Length + 32);\n        int i = 0;\n        while (i < formula.Length)\n        {\n            char c = formula[i];\n            if (c == '\"')","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Formula/ModernFunctionQualifier.cs#L282-L318","documentation":"Thrown by ModernFunctionQualifier.Qualify when an Excel inline array constant {...} contains a non-literal element. Excel inline arrays may hold only literal values (numbers, quoted text, TRUE/FALSE, errors); a function call, cell reference, name, or nested array inside {...} makes Excel report the whole workbook as corrupt. Qualify rejects it at write time.","triggerScenarios":"Writing a formula containing an inline array with a non-literal element, e.g. ={SUM(A1:A3),1} or ={A1,B1}. FindNonLiteralArrayConstant detects the offending element and Qualify throws before the formula is written.","commonSituations":"Building an array literal from cell references instead of a range; putting a function call inside {...}; confusing Excel array constants with a general list syntax.","solutions":["Replace references/functions inside {...} with literal values, or use a cell range (e.g. A1:A3) instead of an inline array.","Move computed values into cells and reference the range.","Ensure array constants contain only numbers, \"text\", TRUE/FALSE, or error literals."],"exampleFix":"// before\nformula = \"={SUM(A1:A3),1}\"; // function inside array\n// after\nformula = \"=A1:A3\"; // reference the range directly","handlingStrategy":"validation","validationCode":"// Only literals allowed inside inline array constants.\nstatic bool IsSafeInlineArray(string formula)\n    => ModernFunctionQualifier.FindNonLiteralArrayConstant(formula) is null;","typeGuard":null,"tryCatchPattern":"try { ModernFunctionQualifier.Qualify(formula); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid array constant\"))\n{ /* switch to a cell range */ }","preventionTips":["Use cell ranges (A1:A3) instead of inline arrays of references.","Keep inline array elements to literals only."],"tags":["excel","formula","array-constant","validation","corruption-prevention"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}