Microsoft KB Archive/921500

= FIX: An incorrect overridden method is called when many classes are derived from a single base class in Visual Studio .NET 2003 =

Article ID: 921500

Article Last Modified on 1/26/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition

-



SYMPTOMS
When you try to call a method in a class that is derived from a base class in Microsoft Visual Studio .NET 2003, the overriden method in the derived class is not called. Instead, the method in the base class is called.

This problem occurs when many classes are derived from a single base class.



CAUSE
This problem occurs because of a problem in the Microsoft Visual Basic .NET 2003 compiler.



RESOLUTION
A supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack for Visual Studio .NET 2003 and the next service pack for the Microsoft .NET Framework 1.1 that contains this hotfix.

To resolve this problem immediately, contact Microsoft Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites
There are no prerequisites for installing this hotfix.

Restart requirement
You do not have to restart your computer after you apply this hotfix.

Hotfix replacement information
This hotfix does not replace any other hotfixes.

File information
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.

Computers that have Visual Studio .NET 2003 installed
Note If you have Visual Studio 2003 Service Pack 1 (SP1) installed, you do not have to apply this hotfix package.

Microsoft Windows Server 2003-based computers that have the Microsoft .NET Framework 1.1 installed
Note You must apply this hotfix package even if you apply the hotfix for Visual Studio .NET 2003.

Computers without Windows Server 2003 that have the Microsoft .NET Framework 1.1 installed
Note You must apply this hotfix package even if you apply the hotfix for Visual Studio .NET 2003.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce this problem
 Use Visual Basic to create a new Windows Application project. To do this, follow these steps:  Start Visual Studio .NET 2003. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects, and then click Windows Application. In the Name box, type EqualsTest, and then click OK.

By default, a new Windows Application project that is named EqualsTest is created, and the Form1 form opens in Design view. Click Form1.</li> In the Properties window, set the Name property to EqualsTestForm, and then press ENTER.

NoteForm1 is renamed EqualsTestForm.</li> Add a ListBox control to the EqualsTestForm form.</li> In the Properties window, set the Name property to codeSelect, and then press ENTER.</li> Add a second ListBox control to the EqualsTestForm form.</li> In the Properties window, set the Name property to codeFieldSelect, and then press ENTER.</li> Add a Button control to the EqualsTestForm form.</li> In the Properties window, set the Text property to Select, and then press ENTER.</li>  Double-click the EqualsTestForm form, and then replace the code for the EqualsTestForm_Load method with the following code example. Private Sub EqualsTestForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim myArray As CodeField = New CodeField { _ New CodeField(&quot;AA&quot;, &quot;1&quot;), _ New CodeField(&quot;BB&quot;, &quot;2&quot;), _ New CodeField(&quot;CC&quot;, &quot;3&quot;), _ New CodeField(&quot;DD&quot;, &quot;4&quot;), _ New CodeField(&quot;EE&quot;, &quot;5&quot;), _ New CodeField(&quot;FF&quot;, &quot;6&quot;), _ New CodeField(&quot;GG&quot;, &quot;7&quot;), _ New CodeField(&quot;HH&quot;, &quot;8&quot;), _ New CodeField(&quot;II&quot;, &quot;9&quot;), _ New CodeField(&quot;JJ&quot;, &quot;10&quot;), _ New CodeField(&quot;KK&quot;, &quot;11&quot;), _ New CodeField(&quot;LL&quot;, &quot;12&quot;), _ New CodeField(&quot;MM&quot;, &quot;13&quot;), _ New CodeField(&quot;NN&quot;, &quot;14&quot;), _ New CodeField(&quot;OO&quot;, &quot;15&quot;), _ New CodeField(&quot;PP&quot;, &quot;16&quot;)}

Me.codeFieldSelect.Items.AddRange(myArray)

Me.codeSelect.Items.Add(&quot;AA&quot;) Me.codeSelect.Items.Add(&quot;BB&quot;) Me.codeSelect.Items.Add(&quot;CC&quot;) Me.codeSelect.Items.Add(&quot;DD&quot;) Me.codeSelect.Items.Add(&quot;EE&quot;) Me.codeSelect.Items.Add(&quot;FF&quot;) Me.codeSelect.Items.Add(&quot;GG&quot;) Me.codeSelect.Items.Add(&quot;HH&quot;) Me.codeSelect.Items.Add(&quot;II&quot;) Me.codeSelect.Items.Add(&quot;JJ&quot;) Me.codeSelect.Items.Add(&quot;KK&quot;) Me.codeSelect.Items.Add(&quot;LL&quot;) Me.codeSelect.Items.Add(&quot;MM&quot;) Me.codeSelect.Items.Add(&quot;NN&quot;) Me.codeSelect.Items.Add(&quot;OO&quot;) Me.codeSelect.Items.Add(&quot;PP&quot;) End Sub </li>  Click the Form1.vb [Design] tab, double-click Select, and then replace the code for the Button1_Click method with the following code example. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Not IsNothing(codeSelect.SelectedItem) Then Dim myCode As New CodeField(DirectCast(codeSelect.SelectedItem, String)) Me.codeFieldSelect.SelectedIndex = Me.codeFieldSelect.Items.IndexOf(myCode) End If   End Sub </li> In Solution Explorer, right-click EqualsTest, point to Add, and then click Add Class.</li> Type CodeField.vb, and then click Open.

A new class that is named CodeField is added to the solution, and CodeField.vb appears.</li>  Replace the code in CodeField.vb with the following code example. Option Strict On

<Serializable> _ Public Class CodeField

Public Overloads Overrides Function Equals(ByVal anObject As Object) As Boolean
 * 1) Region &quot;Equals&quot;

Dim myReturn As Boolean = False If IsNothing(anObject) _ OrElse _ Not Me.GetType Is anObject.GetType Then myReturn = False

Else myReturn = (Me.code = DirectCast(anObject _ , CodeField).code) End If

Return myReturn End Function
 * 1) End Region


 * 1) Region &quot;Properties&quot;

Private mCode As String Private mDescription As String

Public Property code As String Get Return mCode End Get Set(ByVal Value As String) mCode = Value End Set End Property Public Property description As String Get Return mDescription End Get Set(ByVal Value As String) mDescription = Value End Set End Property

Public Overrides Function ToString As String Return Me.code & &quot; -- &quot; & Me.description.Trim End Function
 * 1) End Region

Public Sub New Me.New(&quot;&quot;, &quot;&quot;) End Sub Public Sub New(ByVal aCode As String) Me.New(aCode, &quot;&quot;) End Sub Public Sub New(ByVal aCode As String, ByVal aDescription As String) MyBase.New Me.code = aCode Me.description = aDescription End Sub
 * 1) Region &quot;New constructors&quot;
 * 1) End Region

End Class </li></ol> </li> Run the application. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> On the Debug menu, click Start.</li> Click AA, and then click Select.

NoteAA --1 is selected in the second list. This behavior indicates that the correct version of the Equals method is used in the CodeField class.</li> <li>Close the Form1 form.</li></ol> </li> <li>Modify the application to reproduce the problem. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>In Solution Explorer, right-click EqualsTest, point to Add, click Add Class, type AnotherClass.vb, and then click Open.

Note A new class that is named AnotherClass is added to the solution, and AnotherClass.vb appears.</li> <li> Replace the code that is in AnotherClass.vb with the following code example. Option Strict On

<Serializable> _ Public Class AnotherClass

' This code works fine. Public Overloads Function equals(ByVal anObject As String) As Boolean Return MyBase.equals(anObject) End Function

End Class </li></ol> </li> <li>Run the application. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Debug menu, click Start.</li> <li>Click AA, and then click Select.

Notes <ul> <li>No change occurs in the second list and AA --1 is not selected. This behavior indicates that an incorrect version of the Equals method is used.</li> <li>If you repeat this step after you apply the hotfix, AA --1 is selected in the second list. This behavior indicates that the correct version of the Equals method is used in the CodeField class.</li></ul> </li></ol> </li></ol>

Keywords: kbnetframe110sp2fix kbvsnet2003sp1fix kbinheritance kbcode kbexpertiseinter kbqfe kbupdate kbbug kbprb kbhotfixserver kbfix KB921500

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.