microsoft/aspire · error · ArgumentException

Manifest field numeric values must be finite.

Error message

Manifest field numeric values must be finite.

What it means

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.

Solutions

  1. Check the source of the float with float.IsFinite before passing it to WithField and fix the computation producing NaN/Infinity
  2. Clamp or substitute a default for non-finite values before manifest generation
  3. If infinity is intended, encode it as a string (e.g. "Infinity") or a large sentinel number JSON supports

Example fix

// before
var replicas = desired / current; // can be NaN or Infinity
manifest.WithField("spec.replicas", replicas);
// after
var replicas = current == 0 ? 1 : desired / current;
manifest.WithField("spec.replicas", replicas);
Defensive patterns

Strategy: validation

Validate before calling

if (!float.IsFinite(value)) throw new InvalidOperationException($"Field value {value} must be finite before manifest generation.");

Type guard

static bool IsUsableFloat(float f) => float.IsFinite(f);

Try / catch

try { manifest.WithField(path, value); } catch (ArgumentException ex) when (ex.Message.Contains("finite")) { manifest.WithField(path, 0); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/0ac516f1636fde53. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs:166

            byte or sbyte or short or ushort or int or uint or long or ulong => value,
            float floatValue => NormalizeFloatingPointValue(floatValue),
            double doubleValue => NormalizeFloatingPointValue(doubleValue),
            decimal decimalValue => NormalizeDecimalValue(decimalValue),
            JsonElement element => NormalizeJsonElement(element),
            JsonNode node => NormalizeJsonNode(node),
            IDictionary dictionary => NormalizeDictionary(dictionary),
            IEnumerable enumerable when value is not string => NormalizeEnumerable(enumerable),
            _ => throw new ArgumentException($"Manifest field values must be JSON-compatible primitives, dictionaries, or arrays. Type '{value.GetType()}' is not supported.", nameof(value))
        };
    }

    private const double MaxLongExclusiveAsDouble = 9_223_372_036_854_775_808d;

    private static object NormalizeFloatingPointValue(float value)
    {
        if (!float.IsFinite(value))
        {
            throw new ArgumentException("Manifest field numeric values must be finite.", nameof(value));
        }

        if (MathF.Truncate(value) == value)
        {
            return ConvertWholeNumberToLong(value);
        }

        return value;
    }

    private static object NormalizeFloatingPointValue(double value)
    {
        if (!double.IsFinite(value))
        {
            throw new ArgumentException("Manifest field numeric values must be finite.", nameof(value));
        }

        if (Math.Truncate(value) == value)

View on GitHub (pinned to 25830f84bd)