{"record":{"id":"a011f44b60161ac6","repo":"microsoft/aspire","slug":"whole-number-manifest-field-values-must-be-between-long","errorCode":null,"errorMessage":"Whole-number manifest field values must be between {long.MinValue} and {long.MaxValue}.","messagePattern":"Whole-number manifest field values must be between (.+?) and (.+?)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs","lineNumber":206,"sourceCode":"\n        return value;\n    }\n\n    private static object NormalizeDecimalValue(decimal value)\n    {\n        if (decimal.Truncate(value) == value && value >= long.MinValue && value <= long.MaxValue)\n        {\n            return decimal.ToInt64(value);\n        }\n\n        return value;\n    }\n\n    private static long ConvertWholeNumberToLong(double value)\n    {\n        if (value < long.MinValue || value >= MaxLongExclusiveAsDouble)\n        {\n            throw new ArgumentException($\"Whole-number manifest field values must be between {long.MinValue} and {long.MaxValue}.\", nameof(value));\n        }\n\n        return (long)value;\n    }\n\n    private static object? NormalizeJsonNode(JsonNode node)\n    {\n        using var document = JsonDocument.Parse(node.ToJsonString());\n\n        return NormalizeJsonElement(document.RootElement);\n    }\n\n    private static object? NormalizeJsonElement(JsonElement element)\n    {\n        return element.ValueKind switch\n        {\n            JsonValueKind.Null => null,\n            JsonValueKind.String => element.GetString(),","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs#L188-L224","documentation":"Whole-number floating-point field values are converted to long for exact JSON output; this error is thrown when the value is outside the long range (< long.MinValue or >= 2^63). The library refuses a lossy conversion instead of silently overflowing the JSON integer.","triggerScenarios":"Calling WithField with a float or double whose truncated value is >= 9223372036854775808 or < -9223372036854775808 — e.g. byte capacities expressed in bytes exceeding long range, or accidentally passing a value in the wrong unit.","commonSituations":"Specifying huge storage quantities in bytes instead of Gi, or computing large products (multiplied sizes/counts) that overflow long. Also occurs when double precision rounds a value up to exactly 2^63.","solutions":["Express the value in a smaller unit (e.g. Gi instead of bytes) so it fits in long","Use a string representation of the number if the Kubernetes field accepts strings (e.g. Quantity fields)","Validate the value against long.MinValue/long.MaxValue before passing and split or scale it"],"exampleFix":"// before\nmanifest.WithField(\"spec.capacity.storage\", 10L * 1024 * 1024 * 1024 * 1024 * 1024 * 3); // overflows long\n// after\nmanifest.WithField(\"spec.capacity.storage\", \"30Ti\"); // Kubernetes quantity string","handlingStrategy":"validation","validationCode":"if (value >= 9223372036854775808d || value < -9223372036854775808d) throw new InvalidOperationException(\"Whole-number field value exceeds long range.\");","typeGuard":"static bool FitsInLong(double d) => Math.Truncate(d) == d && d >= long.MinValue && d < 9223372036854775808d;","tryCatchPattern":"try { manifest.WithField(path, value); } catch (ArgumentException ex) when (ex.Message.Contains(\"between\")) { manifest.WithField(path, value.ToString(CultureInfo.InvariantCulture)); }","preventionTips":["Express large quantities in larger units (Gi/Ti) instead of raw bytes","Use Kubernetes Quantity strings for huge values","Check Math.Truncate(value) against long bounds before passing"],"tags":["kubernetes","manifest","numeric","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}