{"record":{"id":"08d1a32782c46c7d","repo":"microsoft/autogen","slug":"unable-to-convert-value-to-enum-typetoconvert-08d1a3","errorCode":null,"errorMessage":"Unable to convert \"{value}\" to enum {typeToConvert}.","messagePattern":"Unable to convert \"(.+?)\" to enum (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs","lineNumber":26,"sourceCode":"\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\n        if (attribute != null)\n        {\n            writer.WriteStringValue(attribute.Name);\n        }\n        else\n        {\n            writer.WriteStringValue(value.ToString());\n        }\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Converters/JsonPropertyNameEnumConverter.cs#L8-L44","documentation":"JsonPropertyNameEnumConverter<T>.Read iterates the enum's fields and matches the incoming JSON string against each field's [JsonPropertyName] name. If no field's attribute name equals the string, conversion is impossible and this JsonException (echoing the value and enum type) is thrown.","triggerScenarios":"The Mistral API returns an enum string the SDK does not know — e.g. a newly added finish reason, tool type, or model capability not present in the shipped enum fields of the AutoGen.Mistral version in use.","commonSituations":"Mistral ships a new finish_reason/tool variant after the package was released; using a preview/beta Mistral model with extended enums; typos in hand-crafted JSON fed to the client.","solutions":["Update AutoGen.Mistral (and Mistral SDK) to a version whose enums include the new value — the message tells you exactly which string is missing.","If updating is blocked, add the missing [JsonPropertyName] member to a local fork of the enum.","Capture the raw HTTP response to confirm which endpoint/field carried the unknown value before upgrading."],"exampleFix":"// before (SDK enum)\npublic enum FinishReasonEnum { [JsonPropertyName(\"stop\")] Stop, [JsonPropertyName(\"length\")] Length }\n// API returns \"content_filter\" -> JsonException\n\n// after (add the member)\npublic enum FinishReasonEnum { [JsonPropertyName(\"stop\")] Stop, [JsonPropertyName(\"length\")] Length, [JsonPropertyName(\"content_filter\")] ContentFilter }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var response = JsonSerializer.Deserialize<ChatCompletionResponse>(json, options); } catch (JsonException ex) when (ex.Message.Contains(\"Unable to convert\")) { /* capture value + upgrade SDK */ }","preventionTips":["Update AutoGen.Mistral promptly after Mistral API releases","Monitor the exception message for the unknown enum string","Pin tested API/model versions in production"],"tags":["mistral","json","enum","version-drift"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}