Browse Source

Make SessionSettings.FromString robust against malformed saved values.

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) <noreply@anthropic.com>
pull/3732/head
Siegfried Pammer 4 months ago
parent
commit
eec031a220
  1. 7
      ILSpy/SessionSettings.cs

7
ILSpy/SessionSettings.cs

@ -162,15 +162,18 @@ namespace ICSharpCode.ILSpy @@ -162,15 +162,18 @@ namespace ICSharpCode.ILSpy
static T FromString<T>(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;
}
}

Loading…
Cancel
Save