{"record":{"id":"13ab04ccca03a501","repo":"iOfficeAI/OfficeCLI","slug":"invalid-propertyname-value-value-expected","errorCode":null,"errorMessage":"Invalid '{propertyName}' value '{value}'. Expected an integer.","messagePattern":"Invalid '(.+?)' value '(.+?)'\\. Expected an integer\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ParseHelpers.cs","lineNumber":421,"sourceCode":"        if (string.IsNullOrWhiteSpace(raw)) return null;\n        raw = raw.Trim();\n        if (int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i))\n            return i;\n        // Accept a decimal string (\"0.0\", \"9440.0\", \"12.5\") and truncate.\n        if (double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out var d)\n            && !double.IsNaN(d) && !double.IsInfinity(d)\n            && d >= int.MinValue && d <= int.MaxValue)\n            return (int)d;\n        return null;\n    }\n\n    /// <summary>\n    /// Safely parse a string as int, throwing ArgumentException with a clear message on failure.\n    /// </summary>\n    public static int SafeParseInt(string value, string propertyName)\n    {\n        if (!int.TryParse(value, CultureInfo.InvariantCulture, out var result))\n            throw new ArgumentException($\"Invalid '{propertyName}' value '{value}'. Expected an integer.\");\n        return result;\n    }\n\n    /// <summary>\n    /// Parse a \"start:end\" character-range spec into 0-based, half-open offsets.\n    /// Colon separator mirrors the officecli range convention (Excel A1:B2).\n    /// Shared by the pptx and docx run-range formatting paths so the two never\n    /// diverge (CONSISTENCY(char-range)).\n    /// </summary>\n    public static (int Start, int End) ParseCharRange(string spec)\n    {\n        var parts = spec.Split(':');\n        if (parts.Length != 2\n            || !int.TryParse(parts[0].Trim(), CultureInfo.InvariantCulture, out var start)\n            || !int.TryParse(parts[1].Trim(), CultureInfo.InvariantCulture, out var end))\n            throw new ArgumentException(\n                $\"Invalid range '{spec}'. Expected 'start:end' with 0-based integer \" +\n                \"character offsets (e.g. '6:11').\");","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ParseHelpers.cs#L403-L439","documentation":"Thrown by SafeParseInt when the string cannot be parsed as an int (invariant culture). It is a thin wrapper over int.TryParse that converts the silent failure into an ArgumentException naming the property and offending value. Used for integer-valued OOXML attributes supplied as strings.","triggerScenarios":"Passing \"1.5\", \"abc\", \"\", or \"1_000\" to a property that expects an integer. A float value stringified where an int was required.","commonSituations":"A computed value that became fractional and was stringified; locale formatting inserting a comma; a JSON number parsed as a string with a decimal point.","solutions":["Pass a whole-number string with no separators (e.g. \"100\").","If you have a double, truncate first: ((int)Math.Round(d)).ToString(CultureInfo.InvariantCulture).","Validate with int.TryParse before the call if unknown should not throw."],"exampleFix":"// before\nSafeParseInt(value.ToString(), \"indent\"); // value == 1.5 -> \"1.5\"\n\n// after\nvar i = (int)Math.Round(value);\nSafeParseInt(i.ToString(CultureInfo.InvariantCulture), \"indent\");","handlingStrategy":"validation","validationCode":"if (!int.TryParse(s, CultureInfo.InvariantCulture, out _))\n    s = ((int)Math.Round(double.Parse(s, CultureInfo.InvariantCulture))).ToString(CultureInfo.InvariantCulture);","typeGuard":"static bool IsIntString(string s) => int.TryParse(s, CultureInfo.InvariantCulture, out _);","tryCatchPattern":"try { n = SafeParseInt(s, name); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expected an integer\"))\n{ n = 0; }","preventionTips":["Pass whole-number strings without separators.","Truncate/round doubles to int before stringifying.","Pre-validate with int.TryParse when unknown should not throw."],"tags":["validation","argument","integer","number-format"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}