{"record":{"id":"3c5f050b9681a045","repo":"github/copilot-sdk","slug":"expected-string-for-toolbinaryresulttype","errorCode":null,"errorMessage":"Expected string for ToolBinaryResultType.","messagePattern":"Expected string for ToolBinaryResultType\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Types.cs","lineNumber":686,"sourceCode":"    /// <inheritdoc/>\n    public bool Equals(ToolBinaryResultType other) => string.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase);\n\n    /// <inheritdoc/>\n    public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Value);\n\n    /// <inheritdoc/>\n    public override string ToString() => Value;\n\n    /// <summary>Provides a <see cref=\"JsonConverter{ToolBinaryResultType}\"/> for serializing <see cref=\"ToolBinaryResultType\"/> instances.</summary>\n    [EditorBrowsable(EditorBrowsableState.Never)]\n    public sealed class Converter : JsonConverter<ToolBinaryResultType>\n    {\n        /// <inheritdoc/>\n        public override ToolBinaryResultType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n        {\n            if (reader.TokenType != JsonTokenType.String)\n            {\n                throw new JsonException(\"Expected string for ToolBinaryResultType.\");\n            }\n\n            var value = reader.GetString();\n            if (value is null)\n            {\n                throw new JsonException(\"ToolBinaryResultType value cannot be null.\");\n            }\n\n            return new ToolBinaryResultType(value);\n        }\n\n        /// <inheritdoc/>\n        public override void Write(Utf8JsonWriter writer, ToolBinaryResultType value, JsonSerializerOptions options) =>\n            writer.WriteStringValue(value.Value);\n    }\n}\n\n/// <summary>","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Types.cs#L668-L704","documentation":"The ToolBinaryResultType JsonConverter.Read requires the incoming JSON token to be a string, since ToolBinaryResultType wraps a string value. It throws this JsonException for any other token type (number, object, array, etc.).","triggerScenarios":"Deserializing JSON where a tool binary result type field is not a string, e.g. `\"resultType\": 3` or `\"resultType\": {...}` passed to JsonSerializer.Deserialize of a model containing ToolBinaryResultType.","commonSituations":"Malformed payloads from external tool runners; schema drift where the field became numeric; hand-constructed JSON in tests.","solutions":["Ensure the JSON field is a string value matching a known ToolBinaryResultType.","Verify the producing side's schema/version still emits strings.","Make the property nullable if the field can be absent.","Catch JsonException and report the payload path for debugging."],"exampleFix":"// before\n{\"resultType\": 1}\n// after\n{\"resultType\": \"binary\"}","handlingStrategy":"type-guard","validationCode":"using var doc = JsonDocument.Parse(json);\nif (doc.RootElement.GetProperty(\"resultType\").ValueKind != JsonValueKind.String)\n    throw new InvalidDataException(\"resultType must be a string\");","typeGuard":"static bool IsJsonString(JsonElement e) => e.ValueKind == JsonValueKind.String;","tryCatchPattern":"try { result = JsonSerializer.Deserialize<ToolResult>(json); }\ncatch (JsonException ex) { log.LogError(ex, \"ToolBinaryResultType token was not a string\"); }","preventionTips":["Emit result type fields as strings only","Contract-test tool runner output against the model","Pin tool-runner and SDK versions","Schema-validate payloads before deserialization"],"tags":["json","deserialization","dotnet"],"backgroundTag":"invalid-enum-value","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}