{"record":{"id":"0ac516f1636fde53","repo":"microsoft/aspire","slug":"manifest-field-numeric-values-must-be-finite","errorCode":null,"errorMessage":"Manifest field numeric values must be finite.","messagePattern":"Manifest field numeric values must be finite\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs","lineNumber":166,"sourceCode":"            byte or sbyte or short or ushort or int or uint or long or ulong => value,\n            float floatValue => NormalizeFloatingPointValue(floatValue),\n            double doubleValue => NormalizeFloatingPointValue(doubleValue),\n            decimal decimalValue => NormalizeDecimalValue(decimalValue),\n            JsonElement element => NormalizeJsonElement(element),\n            JsonNode node => NormalizeJsonNode(node),\n            IDictionary dictionary => NormalizeDictionary(dictionary),\n            IEnumerable enumerable when value is not string => NormalizeEnumerable(enumerable),\n            _ => throw new ArgumentException($\"Manifest field values must be JSON-compatible primitives, dictionaries, or arrays. Type '{value.GetType()}' is not supported.\", nameof(value))\n        };\n    }\n\n    private const double MaxLongExclusiveAsDouble = 9_223_372_036_854_775_808d;\n\n    private static object NormalizeFloatingPointValue(float value)\n    {\n        if (!float.IsFinite(value))\n        {\n            throw new ArgumentException(\"Manifest field numeric values must be finite.\", nameof(value));\n        }\n\n        if (MathF.Truncate(value) == value)\n        {\n            return ConvertWholeNumberToLong(value);\n        }\n\n        return value;\n    }\n\n    private static object NormalizeFloatingPointValue(double value)\n    {\n        if (!double.IsFinite(value))\n        {\n            throw new ArgumentException(\"Manifest field numeric values must be finite.\", nameof(value));\n        }\n\n        if (Math.Truncate(value) == value)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs#L148-L184","documentation":"This error means a float value passed as a manifest field is NaN, PositiveInfinity, or NegativeInfinity, which JSON cannot represent. The library validates all floating-point field values are finite before converting whole-number floats to long. It is thrown as an ArgumentException with the parameter name of the offending value.","triggerScenarios":"Calling WithField on a KubernetesManifestResource with a float that is float.NaN, float.PositiveInfinity, or float.NegativeInfinity — typically produced by division by zero, overflow, or uninitialized computed values.","commonSituations":"Computing numeric values (replica counts, resource limits) from other data where a division by zero or failed parse yields NaN/Infinity. Because the manifest generation happens later, the stack trace points into manifest normalization, not the faulty computation.","solutions":["Check the source of the float with float.IsFinite before passing it to WithField and fix the computation producing NaN/Infinity","Clamp or substitute a default for non-finite values before manifest generation","If infinity is intended, encode it as a string (e.g. \"Infinity\") or a large sentinel number JSON supports"],"exampleFix":"// before\nvar replicas = desired / current; // can be NaN or Infinity\nmanifest.WithField(\"spec.replicas\", replicas);\n// after\nvar replicas = current == 0 ? 1 : desired / current;\nmanifest.WithField(\"spec.replicas\", replicas);","handlingStrategy":"validation","validationCode":"if (!float.IsFinite(value)) throw new InvalidOperationException($\"Field value {value} must be finite before manifest generation.\");","typeGuard":"static bool IsUsableFloat(float f) => float.IsFinite(f);","tryCatchPattern":"try { manifest.WithField(path, value); } catch (ArgumentException ex) when (ex.Message.Contains(\"finite\")) { manifest.WithField(path, 0); }","preventionTips":["Validate numeric computations with float.IsFinite before use","Avoid dividing by potentially zero denominators","Use double (checked separately) only when float range suffices"],"tags":["kubernetes","manifest","numeric","json"],"backgroundTag":"invalid-argument-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}