Click here to Skip to main content
15,886,857 members
Articles / Programming Languages / C#
Article

Visual Studio 2008 SP1 (C#) IDE bug

Rate me:
Please Sign up or sign in to vote.
3.00/5 (12 votes)
9 Oct 2008Public Domain1 min read 38.8K   81   10   9
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:

C#
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:

C#
...

    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:

C#
...

    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.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer (Senior) CET Electronics
Italy Italy
Played with transistors and ICs before being ten. First approaches to programming (PET Commodore) in the early '80.
Then AppleSoft, TurboPascal, Assembler and VisualBasic.
Currently employed at CET Electronics as lead software developer, involved in creation of industrial control systems.
Loving graphics technologies, I had some great time with SVG.
Since 2006 my primary language is C#, where I am focusing on WPF.

Comments and Discussions

 
GeneralEnigm solved! Pin
Mario Vernari9-Oct-08 19:32
Mario Vernari9-Oct-08 19:32 
GeneralRe: Enigm solved! Pin
Paw Jershauge13-Oct-08 11:31
Paw Jershauge13-Oct-08 11:31 
GeneralBase classes are overridden when constructed Pin
Paw Jershauge9-Oct-08 3:45
Paw Jershauge9-Oct-08 3:45 
AnswerRe: Base classes are overridden when constructed Pin
Günther M. FOIDL9-Oct-08 7:12
Günther M. FOIDL9-Oct-08 7:12 
GeneralRe: Base classes are overridden when constructed Pin
Paw Jershauge9-Oct-08 8:24
Paw Jershauge9-Oct-08 8:24 
GeneralRe: Base classes are overridden when constructed Pin
Mario Vernari9-Oct-08 17:58
Mario Vernari9-Oct-08 17:58 
GeneralVS 2005 Pro Pin
Mario Vernari9-Oct-08 2:35
Mario Vernari9-Oct-08 2:35 
GeneralVisual studio 2008 sp1 development edition Pin
Wim Reymen9-Oct-08 2:22
Wim Reymen9-Oct-08 2:22 
GeneralConfirm Pin
lordguthwulf9-Oct-08 2:18
lordguthwulf9-Oct-08 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.