{"record":{"id":"42c162b46d42a33d","repo":"github/copilot-sdk","slug":"toolbinaryresulttype-value-cannot-be-null","errorCode":null,"errorMessage":"ToolBinaryResultType value cannot be null.","messagePattern":"ToolBinaryResultType value cannot be null\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Types.cs","lineNumber":692,"sourceCode":"    /// <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>\n/// Represents the structured result of a tool execution.\n/// </summary>\npublic sealed class ToolResultObject\n{\n    /// <summary>\n    /// Text result to be consumed by the language model.","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Types.cs#L674-L710","documentation":"Within the ToolBinaryResultType converter, after the token-type check, reader.GetString() can return null (e.g. for certain token states); the converter treats a null string as invalid and throws this JsonException because ToolBinaryResultType cannot be constructed without a value.","triggerScenarios":"reader.GetString() returns null during deserialization of a ToolBinaryResultType — practically when the string token carries no usable value or the reader is in an unexpected state.","commonSituations":"Corrupted or truncated JSON; a custom pipeline reusing a Utf8JsonReader at an unexpected position; exotic null-like string tokens.","solutions":["Ensure the JSON contains a real, well-formed string value for the field.","Re-parse from a complete, valid JSON document rather than a partial buffer.","Validate payloads with a JSON schema before deserializing.","Catch JsonException and rethrow with payload context."],"exampleFix":"// before\nvar v = reader.GetString(); // null\n// after\nvar v = reader.GetString() ?? throw new JsonException(\"missing value\");","handlingStrategy":"try-catch","validationCode":"using var doc = JsonDocument.Parse(json); // ensure full valid JSON first\n_ = doc.RootElement.GetProperty(\"resultType\").GetString() ?? throw new InvalidDataException(\"resultType missing\");","typeGuard":null,"tryCatchPattern":"try { result = JsonSerializer.Deserialize<ToolResult>(json); }\ncatch (JsonException ex) { throw new InvalidDataException(\"malformed ToolBinaryResultType payload\", ex); }","preventionTips":["Parse complete documents, not partial buffers","Avoid manually advancing shared Utf8JsonReader instances","Validate JSON before deserializing","Round-trip test serialization/deserialization"],"tags":["json","deserialization","dotnet","null"],"backgroundTag":"json-unmarshal-failed","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"}