You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A property with a private setter ({ get; private set; }) is saved but loads back as its default, and the next save erases the stored value #362
System.Text.Json writes a public property whose setter is non-public, but skips it when reading unless the property has [JsonInclude]. Nothing fails, so LoadOrCreate (AppDataStorage/AppData.cs:647-653) archives nothing and returns the default value. The next Save()/QueueSave() then writes that default over the user's stored value.
This is the same silent data loss as #341, but a different kind of member. The fix proposed in #341 (JsonObjectCreationHandling.Populate) only helps get-only collections, so it does not cover this case.
varq=PrivSettings.LoadOrCreateIn(root);q.SetVolume(80);q.Save();varq2=PrivSettings.LoadOrCreateIn(root);Console.WriteLine($"private set reloaded Volume={q2.Volume}");q2.Save();Console.WriteLine("after next save file: "+File.ReadAllText(Path.Combine(root,"priv_settings.json")));publicclassPrivSettings:AppData<PrivSettings>{publicintVolume{get;privateset;}=50;publicvoidSetVolume(intv)=>Volume=v;}publicclassInc:AppData<Inc>{[JsonInclude]publicintVolume{get;privateset;}=50;publicvoidSetVolume(intv)=>Volume=v;}
Observed:
private set reloaded Volume=50 (expected 80)
after next save file: { "$id": "1", "Volume": 50 }
[JsonInclude] reloaded Volume=80 (the same class with [JsonInclude] round-trips correctly)
A user who writes the natural encapsulated shape, a public getter with a private setter changed through a method, loses the setting on every restart. Nothing is logged and the corrupt-file archive is never triggered.
Suggested fix
Either:
add a DefaultJsonTypeInfoResolver modifier to AppData.JsonSerializerOptions that lets deserialization use the non-public setters of public properties on AppData<T> types, or
fail loudly: detect serialized members that can't be deserialized and throw or warn instead of silently returning defaults. Also document [JsonInclude] as required.
Acceptance criteria
A round-trip test with a { get; private set; } property passes, or loading that type fails with a clear message instead of silently resetting the value.
The existing round-trip tests still pass.
Related: #341 (the same symptom for get-only collections).
Priority: High. It silently loses data. { get; private set; } is the natural shape for an encapsulated property, and when a class uses it the stored value is reset on every restart. Nothing is logged and no .corrupt archive is written, so users only notice when their settings disappear.
Next step: Pick between the resolver modifier (let deserialization use non-public setters on AppData<T> types) and fail-loud detection. The resolver approach keeps user code unchanged. Then add { get; private set; } round-trip tests.
Activity
matt-edmondson commentedon Nov 2, 2026
Triage
{ get; private set; }is the natural shape for an encapsulated property, and when a class uses it the stored value is reset on every restart. Nothing is logged and no.corruptarchive is written, so users only notice when their settings disappear.AppDataStorage/AppData.cs, inJsonSerializerOptionsand the type-info resolver. It's the same area as Get-only collection properties (List<string> Items { get; } = []) are saved but load back empty, and the next save erases them #341, so one person should take both.List<string> Items { get; } = []) are saved but load back empty, and the next save erases them #341 has the same symptom for get-only collections, but its proposed fix (JsonObjectCreationHandling.Populate) doesn't cover this case. A singleDefaultJsonTypeInfoResolvermodifier could probably fix both, so design them together. No open PR covers either. Regenerate CompatibilitySuppressions.xml after the Polyfill 11.4.5 bump [patch] #359 (open) has to land before a release can ship.AppData<T>types) and fail-loud detection. The resolver approach keeps user code unchanged. Then add{ get; private set; }round-trip tests.Generated by Claude Code
Load properties whose setter is private or internal [patch]