BUG: "Event '<Event Name>' cannot be found" error when you upgrade a Visual Basic 6.0 project to Visual Basic .NET (814329)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)

SYMPTOMS

When you upgrade a Microsoft Visual Basic 6.0 project with a user control that has user-defined events to Microsoft Visual Basic .NET, you may receive the following error:
Event 'Event Name' cannot be found.

CAUSE

The error occurs only if you use Visual Basic .NET reserved words as event names. For example, if you have a custom event named Controls in Visual Basic 6.0, and you upgrade the project to Visual Basic .NET by using Visual Basic Upgrade Wizard, you receive the following error message:
Event 'Controls' cannot be found.
When the Wizard tries to upgrade the Visual Basic 6.0 project to Visual Basic .NET, it encounters a conflict. The conflict occurs because Controls is a reserved word that you use as an event name. Therefore, the Wizard renames the declaration of the Controls event to Controls_Renamed, and tries to call the Controls_Renamed event handler when the event is raised. However, the Wizard does not rename the event handler that handles the Controls event to Controls_Renamed. Therefore, you receive the compilation error.

WORKAROUND

To work around this problem, rename the event in the event handler method, as follows:

Change
Private Sub UserControl11_Controls(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles UserControl11.Controls
to
Private Sub UserControl11_Controls(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles UserControl11.Controls_Renamed

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 apply to Microsoft Visual Basic .NET (2002).

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Microsoft Visual Basic 6.0, and then create a new Standard EXE project.
  2. On the Project menu, point to Add User Control, and then click Open.

    UserControl1 is added to the project.
  3. Select Usercontrol1, and then click Code on the View menu.
  4. Add the following code to UserControl1.vb.
    Event Controls()
    Public Sub Procedure1()
       RaiseEvent Controls
    End Sub
  5. Save, and then close the UserControl1 designer.
  6. On the toolbox, double-click UserControl1.

    By default, UserControl11 is added to the form.
  7. Click to select Form1.
  8. On the View menu, click Code.
  9. Add the following code:
    Private Sub Form_Load()
       UserControl11.Procedure1
    End Sub
    
    Private Sub UserControl11_Controls()
       MsgBox ("Hello World")
    End Sub
  10. Save the project, and then exit Visual Basic 6.0.
  11. Start Visual Studio .NET 2003.
  12. On the File menu, click Open, and then click Project.
  13. Click to select Project1.vbp, and then click Open to activate Visual Basic Upgrade Wizard.
  14. Click Next on each page of the Wizard to move to the next page. Click Yes when you are prompted to create a new folder for the project.
  15. 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:kbvs2005doesnotapply kbvs2005swept kbCtrl kbmigrate kbwizard kbUpgrade kbEvent kbControl kbbug KB814329 kbAudDeveloper