{"record":{"id":"d521c51ab28060fa","repo":"microsoft/aspire","slug":"manifest-field-values-must-be-json-compatible-primitives","errorCode":null,"errorMessage":"Manifest field values must be JSON-compatible primitives, dictionaries, or arrays. Type '{value.GetType()}' is not supported.","messagePattern":"Manifest field values must be JSON-compatible primitives, dictionaries, or arrays\\. Type '(.+?)' is not supported\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs","lineNumber":156,"sourceCode":"        current[segments[^1]] = value;\n    }\n\n    internal static object? NormalizeManifestValue(object? value)\n    {\n        return value switch\n        {\n            null => null,\n            string => value,\n            bool => value,\n            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;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs#L138-L174","documentation":"This error means a value passed to a Kubernetes manifest field (via WithField) is not representable as JSON. The library normalizes manifest values to JSON-compatible primitives, dictionaries, and arrays before emitting YAML/JSON, and throws this ArgumentException for any other type. It exists to guarantee the generated manifest is always valid, serializable JSON.","triggerScenarios":"Calling WithField on a KubernetesManifestResource (or nesting a dictionary/array inside one) with a value whose runtime type is not a string, bool, numeric type, JsonElement, JsonNode, IDictionary, or IEnumerable — e.g. a custom class, DateTime, Guid, or a struct.","commonSituations":"Developers pass domain objects, DateTime/DateTimeOffset values, or enums directly as field values, assuming auto-conversion. Since manifest fields come from generic object parameters, the compiler cannot catch this; it only fails at manifest generation time.","solutions":["Convert the value to a JSON-compatible type before passing it: strings, bools, long/int/double/decimal/float, IDictionary with string keys, or IEnumerable","Convert DateTime/DateTimeOffset to an ISO-8601 string with .ToString(\"O\") before passing","Wrap custom objects in a Dictionary<string, object?> with the desired properties","Serialize the object to JsonNode/JsonElement via JsonSerializer.SerializeToNode and pass that"],"exampleFix":"// before\nbuilder.AddKubernetesManifest(\"svc\", manifest => manifest.WithField(\"spec.metadata.createdAt\", DateTime.UtcNow));\n// after\nbuilder.AddKubernetesManifest(\"svc\", manifest => manifest.WithField(\"spec.metadata.createdAt\", DateTime.UtcNow.ToString(\"O\")));","handlingStrategy":"validation","validationCode":"static bool IsJsonCompatible(object? value) => value is null or string or bool or sbyte or byte or short or ushort or int or uint or long or ulong or float or double or decimal or JsonElement or JsonNode or IDictionary or (IEnumerable and not string);","typeGuard":"if (value is not (null or string or bool or int or long or double or float or decimal or JsonElement or JsonNode or IDictionary or IEnumerable)) throw new ArgumentException($\"Unsupported manifest field type {value.GetType()}\");","tryCatchPattern":"try { manifest.WithField(path, value); } catch (ArgumentException ex) when (ex.Message.Contains(\"JSON-compatible\")) { /* fall back: serialize value to JsonNode */ }","preventionTips":["Only pass primitives, string-keyed dictionaries, and enumerables to WithField","Convert DateTime/Guid/enum values to strings explicitly","Use JsonSerializer.SerializeToNode for complex objects"],"tags":["kubernetes","manifest","json-serialization","argument-validation"],"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"}