From eec031a220c609f62b16f20efd7ef3755402db33 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 8 May 2026 21:26:12 +0200 Subject: [PATCH] Make SessionSettings.FromString robust against malformed saved values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The helper used to catch only FormatException, but the WPF type converters (e.g. RectConverter for the saved window placement) raise InvalidOperationException on malformed input — for instance, an empty string from a partially-written config file. That was enough to propagate up through SessionSettings.LoadFromXml and crash startup before the main window could even open, with no recovery path other than manually editing the on-disk ILSpy.xml. Treat any conversion failure as "use the default" instead, and treat empty strings the same as null at the entry. Effect: a single bad saved value falls back silently and the application starts. Co-Authored-By: Claude Opus 4.7 (1M context) --- ILSpy/SessionSettings.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ILSpy/SessionSettings.cs b/ILSpy/SessionSettings.cs index de72f0696..48a1b1296 100644 --- a/ILSpy/SessionSettings.cs +++ b/ILSpy/SessionSettings.cs @@ -162,15 +162,18 @@ namespace ICSharpCode.ILSpy static T FromString(string s, T defaultValue) { - if (s == null) + if (string.IsNullOrEmpty(s)) return defaultValue; try { TypeConverter c = TypeDescriptor.GetConverter(typeof(T)); return (T)c.ConvertFromInvariantString(s); } - catch (FormatException) + catch (Exception) { + // TypeConverters for WPF types (e.g. Rect) throw InvalidOperationException, not + // FormatException, on malformed input. Treat any conversion failure as "use the + // default" so a single bad saved value can't crash startup. return defaultValue; } }