Open
Description
It seems that the CLR is not correctly handling initialization of nullable static variables. The repro steps below should make the problem clearer.
Repro steps:
- Start debugging the following app, either on x86 or x64, for .NET version 3.1.401 or 5.0.100-preview.8.20362.3:
class NullableTest
{
static int? i;
public static void Main()
{
System.Diagnostics.Debugger.Break();
if (i.HasValue)
{
System.Console.WriteLine("Value is {0}!", i.Value);
}
}
}
- Stop at breakpoint;
- Evaluate
i
at the Watch Window. The following error message will show up: "The debugger is unable to evaluate this expression." - Stop at breakpoint and evaluate
i = 2
at the Immediate Window; - Evaluate
i
again, it will now have a value of 2; - Step over twice;
- The condition will be skipped and
i
value is now null.
Regression?
This is a regression when upgrading from 3.1.302 -> 3.1.401. It has also been observed on 5.0.100-preview.3.20216.6 -> 5.0.100-preview.8.20362.3.
Other information
- The CLR is directly returning a null slot for the variable until that value is actually used, which results in the error message shown at step 3. I verified that
ICorDebugReferenceValue::GetValue
returns 0 at that point. - After line 9 is executed,
ICorDebugReferenceValue::GetValue
returns a valid address, which also overwrites any data that was there before (from step 4).