BUG: You receive a "Method not found" error message when you add a UserControl to a form if the UserControl code invokes AXControl methods (316741)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2002)

This article was previously published under Q316741

SYMPTOMS

Under the following circumstances:
  • You build a .NET UserControl.
  • You add a Component Object Model (COM) ActiveX control (AXControl) to the .NET UserControl.
  • Code in the UserControl calls methods from the AXControl.
  • You attempt to add the UserControl to a form in a Windows project.
you receive the following error message:
An exception occurred while trying to create an instance of project name.usercontrol name. The exception was "Method not found: MSComctlLib.ListImages AxMSComctlLib.AxImageList.get_ListImages()."
NOTE: The text of the error message may differ, depending on the control that you use. This particular error message occurred after using the ImageList control. If you receive an exception under similar circumstances when you use a different AXControl, the library or the method that is listed differs.

RESOLUTION

To work around this problem, you can use either of the following methods:

Workaround One

If there is an exact or a similar .NET UserControl version of the control, use the .NET control.

Workaround Two

Add a reference to the AXControl in the client application before you add the UserControl to a form. You do not have to use the AXControl in the client application. You can use the reference only.

To obtain a reference to the AXControl, add the AXControl to the form in the client project. After the control is added to the form, and after the reference is added to the project assembly, remove the AXControl from the form.

You can add an ImageList control to Form1 in the Windows application before you add the UserControl. No exception occurs. You can remove the ImageList control from Form1 either before or after you add the UserControl to the form. However, leave the assembly references to the control as is. You can see the assembly references in Solution Explorer. View the assembly references that are listed in the References node that follows your project name.

STATUS

This bug was corrected in Visual Basic .NET (2002) and Visual C# .NET (2002).

MORE INFORMATION

Steps to Reproduce Behavior in Visual Basic .NET

  1. Open a new Windows Control Library project in Visual Basic .NET.
  2. Add the ActiveX ImageList control (MSComctl.ocx) to the toolbox.
  3. Add an ImageList control (which is listed as ImageControlctrl in the toolbox) to UserControl.
  4. Add the following line of code to the UserControl class file, immediately after the Inherits System.Windows.Forms.UserControl statement:
    Public IconsSmall As MSComctlLib.ListImages
  5. Add the following line of code to the constructor of the form, immediately after the InitializeComponent() call:
    IconsSmall = axImageList1.ListImages
    					
  6. Build the project.
  7. Add a Visual Basic .NET Windows Application project to the solution. Form1 is created by default.
  8. In the toolbox, double-click UserControl1 to add this control to Form1. You receive the error message that is listed in the "Symptoms" section.

Steps to Reproduce Behavior in Visual C# .NET

  1. Open a new Windows Control Library project in Visual C# .NET.
  2. Add the ActiveX ImageList control (MSComctl.ocx) to the toolbox.
  3. Add an ImageList control (which is listed as ImageControlctrl in the toolbox) to UserControl.
  4. Add the following line of code to the UserControl class file, immediately after the private AxMSComctlLib.AxImageList axImageList1; statement:
    Public MSComctlLib.ListImages IconsSmall;
  5. Add the following line of code to the constructor of the form, immediately after the InitializeComponent(); call:
    IconsSmall = axImageList1.ListImages;
    					
  6. Build the project.
  7. Add a Visual C# .NET Windows Application project to the solution. Form1 is created by default.
  8. In the toolbox, double-click UserControl1 to add this control to Form1. You receive the error message that is listed in the "Symptoms" section.

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbbug kbpending KB316741 kbAudDeveloper