65.9K
CodeProject is changing. Read more.
Home

Visual Studio 2008 SP1 (C#) IDE bug

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (12 votes)

Oct 9, 2008

Public Domain

1 min read

viewsIcon

39608

downloadIcon

81

Intellisense debugger fails computation on inheritance

Feel free to download the tiny project for the sample...

Introduction

Before all, this is my very first contribution (and it is NOT a classic application!) and I want to take advantage to thanks many of you that are helping so much the development. I will try hard to write down something useful in the near future, but at the moment I only drop this issue...

Today I have found a dirty bug in the Visual Studio 2008 Sp1 IDE or, at least, in the Visual C# Express since I am using it.

Using the code

The problem itself is tricky, because the (really useful) Intellisense tip showing the value of the variables, just fail on a simple inheritance case.

As you may see on the picture, there are two classes: let B inherited by C.

Now let assuming both B and C have the same property (signature), however with different access modifiers: let the base's property be marked as "virtual" and the derived's one marked as "override".

The "entire" program for test is just below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
            Console.WriteLine(c.Exec());
            Console.ReadKey();
        }
    }



    class B
    {
        public virtual int Value
        {
            get { return 10; }
        }
    }



    class C : B
    {
        public override int Value
        {
            get { return 5; }
        }


        public int Exec()
        {
            return base.Value; //this correctly returns 10
        }
    }
}
		

If you try to run the program, it outputs correctly "10" in the console window...but, what if you try to walk the code and stop just over the line marked with a remark?

Note: place a breakpoint here:

    ...

        public int Exec()
        {
            return base.Value; //place breakpoint here, then hover it
        }
   
    ...

Here is a simple snapshot of the behavior:

Trick!...the tip shows "5" not "10", as I were typed as:

    ...

        public int Exec()
        {
            return this.Value; //that MUST show 5!
        }
   
    ...

Points of Interest

I am assuming that Visual C# Express has the same "engine" of the bigger brother Visual Studio. I was not able to try this snippet inside the "real" Visual Studio Pro or superior. Please, feel free to feedback any different behavior.

History

First release.