{"record":{"id":"f9e6eb03ed29f567","repo":"microsoft/autogen","slug":"value-was-null-f9e6eb","errorCode":null,"errorMessage":"Value was null.","messagePattern":"Value was null\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs","lineNumber":15,"sourceCode":"// Copyright (c) Microsoft Corporation. All rights reserved.\n// JsonPropertyNameEnumConverter.cs\n\nusing System;\nusing System.Reflection;\nusing System.Text.Json;\nusing System.Text.Json.Serialization;\n\nnamespace AutoGen.Mistral;\n\ninternal sealed class JsonPropertyNameEnumConverter<T> : JsonConverter<T> where T : struct, Enum\n{\n    public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        string value = reader.GetString() ?? throw new JsonException(\"Value was null.\");\n\n        foreach (var field in typeToConvert.GetFields())\n        {\n            var attribute = field.GetCustomAttribute<JsonPropertyNameAttribute>();\n            if (attribute?.Name == value)\n            {\n                return (T)Enum.Parse(typeToConvert, field.Name);\n            }\n        }\n\n        throw new JsonException($\"Unable to convert \\\"{value}\\\" to enum {typeToConvert}.\");\n    }\n\n    public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)\n    {\n        var field = value.GetType().GetField(value.ToString());\n        var attribute = field?.GetCustomAttribute<JsonPropertyNameAttribute>();\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs#L1-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var completion = JsonSerializer.Deserialize<ChatCompletionResponse>(json); } catch (JsonException) { /* log raw json, reject payload */ }","preventionTips":["Log raw response bodies when integrating new Mistral endpoints","Keep SDK and AutoGen.Mistral versions in sync","Validate payloads against a schema in CI"],"tags":["mistral","json","deserialization","enum"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}