{"record":{"id":"8aeda4cf71c6dee8","repo":"github/copilot-sdk","slug":"expected-string-for-systemmessagesection","errorCode":null,"errorMessage":"Expected string for SystemMessageSection.","messagePattern":"Expected string for SystemMessageSection\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Types.cs","lineNumber":2312,"sourceCode":"    /// <inheritdoc/>\n    public bool Equals(SystemMessageSection 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{SystemMessageSection}\"/> for serializing <see cref=\"SystemMessageSection\"/> instances.</summary>\n    [EditorBrowsable(EditorBrowsableState.Never)]\n    public sealed class Converter : JsonConverter<SystemMessageSection>\n    {\n        /// <inheritdoc/>\n        public override SystemMessageSection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n        {\n            if (reader.TokenType != JsonTokenType.String)\n            {\n                throw new JsonException(\"Expected string for SystemMessageSection.\");\n            }\n\n            var value = reader.GetString();\n            if (value is null)\n            {\n                throw new JsonException(\"SystemMessageSection value cannot be null.\");\n            }\n\n            return new SystemMessageSection(value);\n        }\n\n        /// <inheritdoc/>\n        public override void Write(Utf8JsonWriter writer, SystemMessageSection value, JsonSerializerOptions options) =>\n            writer.WriteStringValue(value.Value);\n\n        /// <inheritdoc/>\n        public override SystemMessageSection ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>\n            new(reader.GetString()!);","sourceCodeStart":2294,"sourceCodeEnd":2330,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Types.cs#L2294-L2330","documentation":"Thrown by SystemMessageSection's JsonConverter during deserialization when the JSON token for a SystemMessageSection value is not a string. SystemMessageSection is a string-backed, case-insensitive strongly typed value, so only JSON strings are accepted; a number, object, array, or null in that position triggers this. The faulting input is malformed wire data or hand-built JSON rather than caller arguments.","triggerScenarios":"Deserializing JSON where a system message section field is a number, object, array, or null, e.g. `\"section\": {}` where `\"section\": \"intro\"` is expected.","commonSituations":"Schema drift between client and server; hand-written JSON mistakes; serialization of the field by a different language runtime with different typing.","solutions":["Send a string value for the field.","Confirm the server schema still defines the field as a string.","Make the property nullable if the section can be absent.","Catch JsonException and log the token type/position to find the field."],"exampleFix":"// before\n{\"section\": 42}\n// after\n{\"section\": \"overview\"}","handlingStrategy":"type-guard","validationCode":"if (doc.RootElement.GetProperty(\"section\").ValueKind != JsonValueKind.String)\n    throw new InvalidDataException(\"section must be a string\");","typeGuard":"static bool IsJsonString(JsonElement e) => e.ValueKind == JsonValueKind.String;","tryCatchPattern":"try { sm = JsonSerializer.Deserialize<SystemMessage>(json); }\ncatch (JsonException ex) { log.LogError(ex, \"SystemMessageSection token was not a string\"); }","preventionTips":["Ensure section fields are serialized as strings","Contract-test payloads against the model","Align server/client schema versions","Validate JSON schema before deserialization"],"tags":["json","deserialization","dotnet"],"backgroundTag":"type-mismatch","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"}