microsoft/autogen · error · JsonException
Value was null.
Error message
Value was null.
What it means
JsonPropertyNameEnumConverter<T>.Read deserializes Mistral API enums by matching the JSON string against each enum field's [JsonPropertyName] attribute. System.Text.Json guarantees the token is a string for this converter only when the JSON shape matches the contract; a null/absent value where a string is expected surfaces as this JsonException.
Source
Thrown at dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs:15
// Copyright (c) Microsoft Corporation. All rights reserved.
// JsonPropertyNameEnumConverter.cs
using System;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AutoGen.Mistral;
internal sealed class JsonPropertyNameEnumConverter<T> : JsonConverter<T> where T : struct, Enum
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string value = reader.GetString() ?? throw new JsonException("Value was null.");
foreach (var field in typeToConvert.GetFields())
{
var attribute = field.GetCustomAttribute<JsonPropertyNameAttribute>();
if (attribute?.Name == value)
{
return (T)Enum.Parse(typeToConvert, field.Name);
}
}
throw new JsonException($"Unable to convert \"{value}\" to enum {typeToConvert}.");
}
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
var field = value.GetType().GetField(value.ToString());
var attribute = field?.GetCustomAttribute<JsonPropertyNameAttribute>();
View on GitHub (pinned to 027ecf0a37)
Solutions
- Log the raw JSON response body to find which enum field arrived as null.
- Update the AutoGen.Mistral package if the API contract changed (newer models mark such fields optional).
- Pre-validate payloads: reject/null-check response JSON before deserialization when the field must exist.
- Report the field name upstream so the converter/model can be made null-tolerant.
Defensive patterns
Strategy: try-catch
Try / catch
try { var completion = JsonSerializer.Deserialize<ChatCompletionResponse>(json); } catch (JsonException) { /* log raw json, reject payload */ } Prevention
- Log raw response bodies when integrating new Mistral endpoints
- Keep SDK and AutoGen.Mistral versions in sync
- Validate payloads against a schema in CI
When it happens
Trigger: A Mistral API response contains an explicit JSON null (or a malformed payload handled as null) where an enum decorated with this converter is expected — e.g. a null tool_call finish reason or null role field in a chat completion.
Common situations: Mistral API updates that make previously-required enum fields nullable; deserializing error payloads or partial streaming chunks with missing enum fields; schema drift between the SDK models and the live API.
Related errors
- Unable to convert "{value}" to enum {typeToConvert}.
- Failed to deserialize response
- choice.Message.Content
- choice.Message.ToolCalls
- Exception of type 'System.Text.Json.JsonException' was throw
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/f9e6eb03ed29f567.
Report an issue: GitHub.