BUG: "Method cannot handle event" error when you build a Visual Basic .NET 2003 project (814328)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)

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_Event Name' cannot handle Event 'Event Name' 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).

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a Standard EXE project by using Microsoft Visual Basic 6.0.
  2. In Project Explorer, right-click Project1, point to Add, point to Class Module, and then click Open.
  3. Add the following code to Class1:
    Public Event Click(I as Integer)
    Public Event CustomEvent()
  4. In Project Explorer, right-click Form1, and then click View Code.
  5. Add the following code to Form1:
    Dim WithEvents theClass As Class1
    
    Private Sub theClass_Click(I as Integer)
       Debug.Print "Click"
    End Sub
    
    Private Sub theClass_CustomEvent()
       Debug.Print "CustomEvent"
    End Sub
  6. Save Class1, Form1, and Project1.
  7. Open Visual Studio .NET (2003), then and press the CTRL+SHIFT+O key combination.

    The Open Project dialog box is displayed.
  8. Locate Project1.vbp as created in Step 7, click to select it, and then click Open to activate the Visual Basic Upgrade Wizard.
  9. 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.
  10. On the Build menu, click Build Solution. Click Save when you are prompted to save Project1.sln.

    You receive the error mentioned in the "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:3/20/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbWindowsForms kbCtrl kbForms kbUpgrade kbMigration kbCodeGen kbbug KB814328 kbAudDeveloper