tui-cs/Terminal.Gui · error · JsonException
{p.Key}: No source-generated JsonTypeInfo is registered for
Error message
{p.Key}: No source-generated JsonTypeInfo is registered for {prop.GetType ().FullName}. What it means
Thrown in ScopeJsonConverter.Write when a configuration property's runtime value type is not registered in the source-generated TuiSerializerContext (which wraps SourceGenerationContext.Default). When the value is not null, not an enum, and has no registered JsonTypeInfo, the serializer cannot emit it without reflection, so it throws. This is the write-side counterpart of error 83.
Source
Thrown at Terminal.Gui/Configuration/ScopeJsonConverter.cs:222
}
object? prop = propertyValue;
if (prop == null)
{
writer.WriteNullValue ();
}
else
{
if (TryWriteEnumValue (writer, prop.GetType (), prop))
{
continue;
}
JsonTypeInfo? jsonTypeInfo = TuiSerializerContext.Instance.GetTypeInfo (prop.GetType ());
if (jsonTypeInfo is null)
{
throw new JsonException ($"{p.Key}: No source-generated JsonTypeInfo is registered for {prop.GetType ().FullName}.");
}
JsonSerializer.Serialize (writer, prop, jsonTypeInfo);
}
}
writer.WriteEndObject ();
}
private static bool CanAcceptNullValue (Type propertyType) => !propertyType.IsValueType || Nullable.GetUnderlyingType (propertyType) is { };
private static object? DeserializePropertyValue (ref Utf8JsonReader reader, Type propertyType, JsonSerializerOptions options)
{
Type? nullableType = Nullable.GetUnderlyingType (propertyType);
Type enumType = nullableType ?? propertyType;
if (enumType.IsEnum)
{View on GitHub (pinned to 2e47b11478)
Solutions
- Add [JsonSerializable(typeof(YourType))] to the SourceGenerationContext partial class so GetTypeInfo returns non-null for the runtime type.
- Ensure the property's declared type matches the runtime type that is registered; if polymorphism is needed, use [JsonPolymorphic] + [JsonDerivedType] on the base.
- Avoid putting unregistered types into ConfigurationManager settings; keep config properties limited to the types already known to TuiSerializerContext.
Example fix
// before
public static IDictionary<string, object> Extras { get; set; }
// runtime value type not registered -> throws on Write
// after
[JsonSerializable (typeof (Dictionary<string, string>))]
internal partial class SourceGenerationContext : JsonSerializerContext { }
// and type the property as Dictionary<string,string> Defensive patterns
Strategy: validation
Validate before calling
// Confirm the runtime type is registered before serializing
Type t = propertyValue!.GetType ();
if (TuiSerializerContext.Instance.GetTypeInfo (t) is null)
throw new InvalidOperationException ($"Type {t} is not registered; add [JsonSerializable] to SourceGenerationContext."); Type guard
static bool IsRegisteredForSerialization (Type t) => SourceGenerationContext.Default.GetTypeInfo (t) is not null;
Try / catch
try { JsonSerializer.Serialize (writer, prop, TuiSerializerContext.Instance.SettingsScope); }
catch (JsonException ex) when (ex.Message.Contains ("No source-generated JsonTypeInfo"))
{ /* register the type or skip the property */ } Prevention
- Add [JsonSerializable(typeof(...))] for every type that can appear as a config property value.
- Prefer concrete sealed types for config properties to avoid polymorphism surprises.
- Add a unit test that serializes a fully-populated SettingsScope and asserts no JsonException.
When it happens
Trigger: Calling any code path that serializes a SettingsScope/ThemeScope back to JSON (ConfigurationManager.ToJson, SourcesManager.ToJson, SourcesManager.ToStream, or the Write override) when a property holds an instance whose GetType() is a type not annotated with [JsonSerializable] on SourceGenerationContext — e.g. a derived type, a newly added config property type, or a boxed struct.
Common situations: Adding a new ConfigurationProperty whose static type is an interface/base class but whose runtime value is a subclass; upgrading Terminal.Gui and forgetting to regenerate the source-gen context; storing a custom record in a config property.
Related errors
- {p.Key}: Unsupported configuration converter type "{converte
- {propertyType.FullName}: No source-generated JsonTypeInfo is
- Unexpected StartObject token when parsing Attribute: {reader
- {propertyName}: Both Foreground and Background colors must b
- {propertyName}: Unsupported configuration converter type "{c
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/cce490884deb83df.
Report an issue: GitHub.