Click here to Skip to main content
Licence Public Domain
First Posted 9 Oct 2008
Views 17,110
Downloads 32
Bookmarked 9 times

Visual Studio 2008 SP1 (C#) IDE bug

By | 9 Oct 2008 | Article
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.

License

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

About the Author

Mario Vernari

Software Developer (Senior)
CET Electronics
Italy Italy

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralEnigm solved! PinmemberMario Vernari19:32 9 Oct '08  
GeneralRe: Enigm solved! PinmemberPaw Jershauge11:31 13 Oct '08  
GeneralBase classes are overridden when constructed PinmemberPaw Jershauge3:45 9 Oct '08  
AnswerRe: Base classes are overridden when constructed PinmemberGünther M. FOIDL7:12 9 Oct '08  
GeneralRe: Base classes are overridden when constructed PinmemberPaw Jershauge8:24 9 Oct '08  
GeneralRe: Base classes are overridden when constructed PinmemberMario Vernari17:58 9 Oct '08  
GeneralVS 2005 Pro PinmemberMario Vernari2:35 9 Oct '08  
GeneralVisual studio 2008 sp1 development edition PinmemberMember 26978412:22 9 Oct '08  
GeneralConfirm Pinmembercodernix2:18 9 Oct '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 9 Oct 2008
Article Copyright 2008 by Mario Vernari
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid