Microsoft KB Archive/814328

= BUG: &quot;Method cannot handle event&quot; error when you build a Visual Basic .NET 2003 project =

Article ID: 814328

Article Last Modified on 3/20/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition

-



SYMPTOMS
In Microsoft Visual Basic .NET (2003), when you upgrade a Microsoft Visual Basic 6.0 project with custom events that have the same name as a Windows Form event or a User Control class event (for example, a Click event), you may receive the following error when you build the project:

Method 'theClass_ ' cannot handle Event ' ' because they do not have the same signature.



CAUSE
This bug occurs because the Visual Basic Upgrade Wizard cannot differentiate between custom events and actual Windows Form or User Control events that have the same name. As a result, the Upgrade Wizard incorrectly upgrades custom events as Windows Form or User Controls events. Therefore, you receive the error.



WORKAROUND
To work around this bug, modify the code that is generated by the Upgrade Wizard for custom events so that Visual Basic .NET (2003) events have the same declaration for the event as the corresponding Visual Basic 6.0 events. For example, upgrade the Click event as follows in Visual Basic .NET: Public Event Click(ByVal Sender As System.Object, ByVal e As System.EventArgs) Delete the parameters for the Click event code, so that the Visual Basic .NET event has same signature as the Visual Basic 6.0 events, as follows: Public Event Click



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug does not occur in Microsoft Visual Basic .NET (2002).



Steps to Reproduce the Behavior
 Create a Standard EXE project by using Microsoft Visual Basic 6.0. In Project Explorer, right-click Project1, point to Add, point to Class Module, and then click Open.  Add the following code to Class1: Public Event Click(I as Integer) Public Event CustomEvent  In Project Explorer, right-click Form1, and then click View Code.  Add the following code to Form1: Dim WithEvents theClass As Class1

Private Sub theClass_Click(I as Integer) Debug.Print &quot;Click&quot; End Sub

Private Sub theClass_CustomEvent Debug.Print &quot;CustomEvent&quot; End Sub  Save Class1, Form1, and Project1.</li> Open Visual Studio .NET (2003), then and press the CTRL+SHIFT+O key combination.

The Open Project dialog box is displayed.</li> Locate Project1.vbp as created in Step 7, click to select it, and then click Open to activate the Visual Basic Upgrade Wizard.</li> Click Next on each page of the Upgrade Wizard to move to the next page. Click Yes when you are prompted to create a new folder for the project.</li> On the Build menu, click Build Solution. Click Save when you are prompted to save Project1.sln.

You receive the error mentioned in the &quot;Symptoms&quot; section of this article.

</li></ol>

Keywords: kbbug kbwindowsforms kbupgrade kbforms kbcodegen kbctrl kbmigration kbvs2005swept kbvs2005doesnotapply KB814328

-

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

© Microsoft Corporation. All rights reserved.