Note: The code works in Windows 11 (22000.1098) and earlier but causes stack overflow exception on Windows 11 (22621.525)
I have a bug that is causing me massive problems in a C# program I'm in charge of. It works well in earlier Windows versions (including earlier Windows 11). It also works in debug builds. But it throws an exception in release build. I have drilled down to the individual functions where the problem appears and it´s weird.
The code is something like
MySettings.MySetting setting = new MySettings.MySetting()
{
Value = Double.NaN,
Values = new double[] { Double.NaN },
Special = "" }
});
but if I change the Double.NaN to a numeric value the code works.
I tried to desimplify it as
MySettings.MySetting setting = new MySettings.MySetting();
set1.Value = Double.NaN;
set1.Values = new double[] { Double.NaN };
set1.Special = "";
Removing Special changes nothing, but if either Value or Values are NaN it throws exception.
The settings class in minimal form is
public class MySetting
{
public Double Value { get; set; }
public string Special { get; set; }
public Double[] Values { get; set; }
public ValueSpecial[] Specials { get; set; }
public ValueSpecial AddSpecial(string code, string value)
{
ValueSpecial special = new ValueSpecial() { Code = code, Value = value };
return special;
}
public void ForgetSpecial(string code)
{
}
public override string ToString()
{
return "Not today";
}
}
ValueSpecial is very simple
public class ValueSpecial
{
public string Code { get; set; }
public string Value { get; set; }
public override string ToString()
{
return "dummy";
}
}
The call stack looks very innocent. Main() -> MainForm() -> InitializeComponent() -> MyControl() so it doesn't appear to be any recursion going on.
What has Microsoft changed in this version of Windows and how do I get around it?
Please note that the same binary works on Windows 11 22000.1098 so don't just focus on the code.
It looks like https://stackoverflow.com/a/25208200/1771388 may give the answer.