Skip to content

Fix #2919: keep a settings file that cannot be parsed - #4109

Merged
siegfriedpammer merged 1 commit into
masterfrom
fix/2919-keep-unreadable-settings
Sep 5, 2026
Merged

siegfriedpammer merged 1 commit into
masterfrom
fix/2919-keep-unreadable-settings

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

Fixes #2919.

ILSpy.xml is the only copy of everything a user puts in it - assembly lists above all, which
people build up over years and, as the report shows, edit by hand. A file that fails to parse was
replaced by defaults on the next save, and a save happens for something as incidental as a window
position, so the data was gone before the user had a chance to notice anything was wrong.

The change

ILSpySettings.Update is the one place that writes the file. When the file cannot be parsed it is
moved to ILSpy.xml.broken-<timestamp> before the new one is written, and an earlier copy is never
replaced - two bad starts in a row must not cost the file that still holds the data. A typo in
hand-written XML is usually one edit away from readable, so what matters is that it still exists.

Failing to move the file does not stop settings from being saved: keeping it is the point, and a
copy that cannot be made is not a reason to lose the session's settings too.

What this does not do

It does not tell the user. The thread's reading was that this is unfixable short of central
settings loading and saving:

until we implement DI with "proper" central loading/saving of settings this is pretty much
unfixable (way too many places reading/writing those files)

That holds for notifying - there is nowhere central to report from, and ICSharpCode.ILSpyX has
no UI to report to. It does not hold for the data loss itself, which is one doc.Save(config) in
one method. So this fixes the destructive half now and leaves the notification to the refactor,
with the file recoverable in the meantime and its name saying why it is there.

Verification

ILSpy.Tests/Settings/MalformedSettingsFileTests, four tests written failing first: what could not
be parsed is kept, the save still goes through, an earlier backup is not overwritten, and a
well-formed file is left completely alone. ILSpy.Tests 1263 tests, no failures.

Prepared by an AI agent (Claude, claude-opus-5, via Claude Code) and reviewed by @siegfriedpammer.

ILSpy.xml is the only copy of everything a user puts in it - assembly
lists above all, which people build up over years and, as the report
shows, edit by hand. A file that fails to parse was replaced by defaults
on the next save, which happens for something as incidental as a window
position, so the data was gone before the user had a chance to notice
anything was wrong.

The file is now moved aside first, under a name that says what it is, and
an earlier copy is never replaced: two bad starts in a row must not cost
the file that still has the data. A typo in hand-written XML is usually
one edit away from readable, so what matters is that it still exists.

Telling the user is still not solved - that needs somewhere central to
report it from, which the settings do not have yet - but the file is
recoverable, and its name says why it is there.

Assisted-by: Claude:claude-opus-5:Claude Code
@siegfriedpammer
siegfriedpammer merged commit 00572ca into master Sep 5, 2026
17 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix/2919-keep-unreadable-settings branch September 5, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assembly List destroyed - data loss

1 participant