github/copilot-sdk · error · JsonException
SystemMessageSection value cannot be null.
Error message
SystemMessageSection value cannot be null.
What it means
After confirming a string token, the SystemMessageSection converter calls reader.GetString(); if it returns null the converter throws this JsonException, since a SystemMessageSection must wrap a concrete string value.
Solutions
- Ensure the JSON is complete and valid before deserializing.
- Provide a non-null string for the field.
- Use a schema validator on the payload first.
- Catch JsonException and wrap it with payload context.
Example fix
// before
{"section": null} // or truncated JSON
// after
{"section": "overview"} Defensive patterns
Strategy: try-catch
Validate before calling
using var doc = JsonDocument.Parse(json); // fail early on malformed input
_ = doc.RootElement.GetProperty("section").GetString() ?? throw new InvalidDataException("section missing"); Try / catch
try { sm = JsonSerializer.Deserialize<SystemMessage>(json); }
catch (JsonException ex) { throw new InvalidDataException("malformed SystemMessageSection", ex); } Prevention
- Never emit null for non-nullable section fields
- Parse full documents before deserializing
- Schema-validate payloads
- Add round-trip serialization tests
When it happens
Trigger: reader.GetString() yields null during deserialization of a SystemMessageSection — typically from an unexpected reader state or a malformed document.
Common situations: Truncated JSON buffers; manually driven Utf8JsonReader misuse; documents where the string token cannot yield a value.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- ToolBinaryResultType value cannot be null.
- Failed to deserialize permission request
- Expected a string token when reading
- Expected a non-empty string token when reading
- Expected string for ToolBinaryResultType.
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/0ba9455279f21f61.
Report an issue: GitHub.
Appendix: source
Thrown at dotnet/src/Types.cs:2318
/// <inheritdoc/>
public override string ToString() => Value;
/// <summary>Provides a <see cref="JsonConverter{SystemMessageSection}"/> for serializing <see cref="SystemMessageSection"/> instances.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class Converter : JsonConverter<SystemMessageSection>
{
/// <inheritdoc/>
public override SystemMessageSection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException("Expected string for SystemMessageSection.");
}
var value = reader.GetString();
if (value is null)
{
throw new JsonException("SystemMessageSection value cannot be null.");
}
return new SystemMessageSection(value);
}
/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, SystemMessageSection value, JsonSerializerOptions options) =>
writer.WriteStringValue(value.Value);
/// <inheritdoc/>
public override SystemMessageSection ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
new(reader.GetString()!);
/// <inheritdoc/>
public override void WriteAsPropertyName(Utf8JsonWriter writer, SystemMessageSection value, JsonSerializerOptions options) =>
writer.WritePropertyName(value.Value);
}
}View on GitHub (pinned to cd8cf15dc3)