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 settings file that loaded before an app update makes every Get() throw InvalidOperationException instead of being archived as .corrupt #353
LoadOrCreate recovers from an unreadable file by archiving it as .corrupt and falling back. The catch filter at AppDataStorage/AppData.cs:672 only matches JsonException, ArgumentException, FormatException and NotSupportedException:
catch(Exceptionex)when(exisJsonException or ArgumentException or FormatException or NotSupportedException)
The serializer options set ReferenceHandler = ReferenceHandler.Preserve (AppData.cs:41). With that setting, System.Text.Json throws InvalidOperationException when a $ref points at an object whose type doesn't fit the property it is assigned to. That exception gets past the filter. The file is not archived, no fallback runs, and because InternalState is PublicationOnly (AppData.cs:459), every later Get() retries and throws again for the rest of the process.
Why it matters
This is the "model change in an app update" case that the comment at AppData.cs:674-676 says the catch handles:
v1 of an app has two properties of the same type that share one instance, so the saved file contains "B": { "$ref": "2" }.
v2 changes the type of B.
On first launch after the update, Settings.Get() throws on every call and the app can't start, even though deleting the file would fix it.
Repro (v1 file written with A and B sharing one Inner; v2 declares B as Other; Settings.Get() called three times):
Get #0: System.InvalidOperationException: The object with reference id '2' of type 'Inner' cannot be assigned to the type 'Other'.
Get #1: (same)
Get #2: (same)
files: settings.json <- not archived, no recovery
LoadOrCreateIn(root) throws the same way on a hand-edited file of that shape.
Suggested fix / acceptance criteria
Add InvalidOperationException to the filter at AppData.cs:672, or otherwise cover every exception the deserializer can raise because of the data rather than the environment.
Add a test: a file whose $ref points at a mismatched type is archived as settings.json.corrupt.<timestamp>, LoadOrCreate returns defaults (or the .tmp/.bk copy when one exists), and Get() doesn't throw.
Priority: High. After an ordinary model change in an app update, every Get() throws for the rest of the process, so a consuming app can fail to start until the user deletes the settings file by hand. This is the exact scenario the recovery path claims to handle, and the fix is small.
Area / suggested assignee: the catch filter at AppData.cs:672, interacting with ReferenceHandler.Preserve (:41) and the PublicationOnly lazy state (:459). Owner: @matt-edmondson
Activity
matt-edmondson commentedon Oct 19, 2026
Triage
Get()throws for the rest of the process, so a consuming app can fail to start until the user deletes the settings file by hand. This is the exact scenario the recovery path claims to handle, and the fix is small.AppData.cs:672, interacting withReferenceHandler.Preserve(:41) and thePublicationOnlylazy state (:459). Owner: @matt-edmondsonList<string> Items { get; } = []) are saved but load back empty, and the next save erases them #341 (load fidelity).InvalidOperationExceptionto the filter, or catch every exception that comes from the data, and add the mismatched-$refarchive test.Generated by Claude Code