{"record":{"id":"0bf46bb541639239","repo":"github/copilot-sdk","slug":"expected-a-non-empty-string-value-when-writing-ty","errorCode":null,"errorMessage":"Expected a non-empty string value when writing {typeToConvert.Name}.","messagePattern":"Expected a non-empty string value when writing (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Types.cs","lineNumber":41,"sourceCode":"        if (reader.TokenType != JsonTokenType.String)\n        {\n            throw new JsonException($\"Expected a string token when reading {typeToConvert.Name}, but found {reader.TokenType}.\");\n        }\n\n        var value = reader.GetString();\n        if (string.IsNullOrWhiteSpace(value))\n        {\n            throw new JsonException($\"Expected a non-empty string token when reading {typeToConvert.Name}.\");\n        }\n\n        return value!;\n    }\n\n    internal static void WriteValue(Utf8JsonWriter writer, string value, Type typeToConvert)\n    {\n        if (string.IsNullOrWhiteSpace(value))\n        {\n            throw new JsonException($\"Expected a non-empty string value when writing {typeToConvert.Name}.\");\n        }\n\n        writer.WriteStringValue(value);\n    }\n}\n\n/// <summary>Diagnostic IDs for the Copilot SDK.</summary>\ninternal static class Diagnostics\n{\n    /// <summary>Indicates an experimental API that may change or be removed.</summary>\n    internal const string Experimental = \"GHCP001\";\n}\n\n/// <summary>\n/// Log level for the Copilot runtime. Use the well-known values exposed as\n/// static members (<see cref=\"None\"/>, <see cref=\"Error\"/>, <see cref=\"Warning\"/>,\n/// <see cref=\"Info\"/>, <see cref=\"Debug\"/>, <see cref=\"All\"/>), or construct\n/// your own with <see cref=\"CopilotLogLevel(string)\"/> if the runtime accepts","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Types.cs#L23-L59","documentation":"GeneratedStringEnumJson.WriteValue validates on serialization that the string being written is non-empty. It throws this JsonException when serializing an object whose string-backed enum property is null, empty, or whitespace, because writing an empty string would produce an invalid enum representation.","triggerScenarios":"Serializing an object where a GeneratedStringEnumJson-backed property is `\"\"`, whitespace, or null (when the converter is invoked for null), e.g. `JsonSerializer.Serialize(new Message { Source = new MessageSource(\"\") })`.","commonSituations":"Objects constructed programmatically with uninitialized string fields; models populated from databases with empty defaults; default-constructed wrappers holding \"\".","solutions":["Initialize the property with a valid enum value before serializing.","Make the property nullable and skip it when null (JsonIgnoreCondition.WhenWritingNull).","Validate the value at construction time (guard in the wrapper type constructor).","Catch JsonException during serialization and log the offending member."],"exampleFix":"// before\nnew MessageSource(\"\")\n// after\nnew MessageSource(\"user\")","handlingStrategy":"validation","validationCode":"// validate before serializing\nif (string.IsNullOrWhiteSpace(message.Source?.Value))\n    throw new InvalidOperationException(\"Source must be a non-empty value before serialization\");","typeGuard":"static bool IsSerializable(MessageSource? s) => !string.IsNullOrWhiteSpace(s?.Value);","tryCatchPattern":"try { JsonSerializer.Serialize(payload); }\ncatch (JsonException ex) { log.LogError(ex, \"payload contains empty string enum value\"); }","preventionTips":["Initialize string-backed enum properties at construction","Guard wrapper-type constructors against empty strings","Use JsonIgnoreCondition.WhenWritingNull for optional enums","Unit-test serialization of all model states"],"tags":["json","serialization","dotnet","empty-string"],"backgroundTag":"empty-required-field","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"}