{"record":{"id":"cce490884deb83df","repo":"tui-cs/Terminal.Gui","slug":"p-key-no-source-generated-jsontypeinfo-is-regis","errorCode":null,"errorMessage":"{p.Key}: No source-generated JsonTypeInfo is registered for {prop.GetType ().FullName}.","messagePattern":"(.+?): No source-generated JsonTypeInfo is registered for (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/ScopeJsonConverter.cs","lineNumber":222,"sourceCode":"            }\n            object? prop = propertyValue;\n\n            if (prop == null)\n            {\n                writer.WriteNullValue ();\n            }\n            else\n            {\n                if (TryWriteEnumValue (writer, prop.GetType (), prop))\n                {\n                    continue;\n                }\n\n                JsonTypeInfo? jsonTypeInfo = TuiSerializerContext.Instance.GetTypeInfo (prop.GetType ());\n\n                if (jsonTypeInfo is null)\n                {\n                    throw new JsonException ($\"{p.Key}: No source-generated JsonTypeInfo is registered for {prop.GetType ().FullName}.\");\n                }\n\n                JsonSerializer.Serialize (writer, prop, jsonTypeInfo);\n            }\n        }\n\n        writer.WriteEndObject ();\n    }\n\n    private static bool CanAcceptNullValue (Type propertyType) => !propertyType.IsValueType || Nullable.GetUnderlyingType (propertyType) is { };\n\n    private static object? DeserializePropertyValue (ref Utf8JsonReader reader, Type propertyType, JsonSerializerOptions options)\n    {\n        Type? nullableType = Nullable.GetUnderlyingType (propertyType);\n        Type enumType = nullableType ?? propertyType;\n\n        if (enumType.IsEnum)\n        {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/ScopeJsonConverter.cs#L204-L240","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic static IDictionary<string, object> Extras { get; set; }\n// runtime value type not registered -> throws on Write\n\n// after\n[JsonSerializable (typeof (Dictionary<string, string>))]\ninternal partial class SourceGenerationContext : JsonSerializerContext { }\n// and type the property as Dictionary<string,string>","handlingStrategy":"validation","validationCode":"// Confirm the runtime type is registered before serializing\nType t = propertyValue!.GetType ();\nif (TuiSerializerContext.Instance.GetTypeInfo (t) is null)\n    throw new InvalidOperationException ($\"Type {t} is not registered; add [JsonSerializable] to SourceGenerationContext.\");","typeGuard":"static bool IsRegisteredForSerialization (Type t) => SourceGenerationContext.Default.GetTypeInfo (t) is not null;","tryCatchPattern":"try { JsonSerializer.Serialize (writer, prop, TuiSerializerContext.Instance.SettingsScope); }\ncatch (JsonException ex) when (ex.Message.Contains (\"No source-generated JsonTypeInfo\"))\n{ /* register the type or skip the property */ }","preventionTips":["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."],"tags":["config","json","serialization","source-generation","aot"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}