microsoft/aspire · error · JsonException
Expected a non-empty Kubernetes MicroTime value.
Error message
Expected a non-empty Kubernetes MicroTime value.
What it means
Thrown by KubernetesMicroTimeJsonConverter.Read when the JSON value is a string but empty (or null-string). Kubernetes MicroTime values must be a non-empty RFC3339 timestamp; the converter rejects empty strings before attempting ParseExact.
Solutions
- Emit null instead of "" when the timestamp is absent.
- Populate the field with a valid RFC3339 UTC string such as "2024-01-01T00:00:00Z".
- Sanitize incoming payloads: replace empty strings with null before deserialization if the source cannot be fixed.
Example fix
// before
{ "lastUpdate": "" }
// after
{ "lastUpdate": null } Defensive patterns
Strategy: validation
Validate before calling
if (payload.LastUpdate is "") payload.LastUpdate = null; // normalize empty to null before deserializing
Type guard
static bool IsValidMicroTime(string? s) => !string.IsNullOrEmpty(s) && DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out _);
Try / catch
try { time = JsonSerializer.Deserialize<KubernetesMicroTime>(ref reader, options); }
catch (JsonException ex) when (ex.Message.Contains("non-empty")) { time = null; /* treat as missing */ } Prevention
- Serialize missing timestamps as null, never as "".
- Use nullable types for optional timestamp fields in fixtures and mocks.
- Validate fixture JSON against the Kubernetes MicroTime format.
When it happens
Trigger: Deserializing JSON where a MicroTime field is "" (empty string). Note a literal JSON null is tolerated earlier and yields null, so this only fires for empty/whitespace strings.
Common situations: Server or mock omitting the timestamp but serializing an empty string instead of null; placeholder fixtures with blank timestamps; partially initialized DCP state.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Expected a string token for Kubernetes MicroTime but found
- Cannot convert string
- Error deserializing GenAI message content. Error description
- Expected PropertyName, got
- Expected StartObject, got
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/068d0681534a5e69.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Dcp/Model/KubernetesMicroTimeJsonConverter.cs:30
private const string UtcFormat = "yyyy-MM-dd'T'HH:mm:ss.ffffff'Z'";
private const string OffsetFormat = "yyyy-MM-dd'T'HH:mm:ss.ffffffzzz";
public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType is JsonTokenType.Null)
{
return null;
}
if (reader.TokenType is not JsonTokenType.String)
{
throw new JsonException($"Expected a string token for Kubernetes MicroTime but found {reader.TokenType}.");
}
var value = reader.GetString();
if (string.IsNullOrEmpty(value))
{
throw new JsonException("Expected a non-empty Kubernetes MicroTime value.");
}
return value.EndsWith('Z')
? DateTime.ParseExact(value, UtcFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)
: DateTimeOffset.ParseExact(value, OffsetFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal).UtcDateTime;
}
public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
{
if (value is null)
{
writer.WriteNullValue();
return;
}
// DCP models these fields as Kubernetes metav1.MicroTime, whose JSON shape is fixed-width:
// "2026-07-15T18:46:06.123000Z"
// See https://github.com/kubernetes/apimachinery/blob/v0.36.0/pkg/apis/meta/v1/micro_time.go.View on GitHub (pinned to 25830f84bd)