Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property value of "base" in debugger

Tags:

I'm debugging the following code:

class A 
{
    public virtual string X => "A";
}

class B : A
{
    public bool OwnX { get; set; } = true;
    public override string X
        => OwnX ? "B" : base.X; // (o)
}

class Program
{
    static void Main() => Console.WriteLine(new B().X);
}

And I have a breakpoint on the line marked with (o). When the breakpoint hit, I'm trying to evaluate base.X and getting its value "B":

strage base.X value?

The question is: why not "A"?

like image 709
ie. Avatar asked Mar 16 '17 15:03

ie.


1 Answers

This is a Roslyn bug

As others have mentioned, this bug is well known.

You can trivially check that the actual value of base.X is A, it is just the Expression Evaluator that returns the wrong result:

This one is in Rider

like image 160
Marcell Toth Avatar answered Oct 14 '22 05:10

Marcell Toth