Microsoft KB Archive/316741

= BUG: You receive a &quot;Method not found&quot; error message when you add a UserControl to a form if the UserControl code invokes AXControl methods =

Article ID: 316741

Article Last Modified on 2/3/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-



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. . The exception was &quot;Method not found: MSComctlLib.ListImages AxMSComctlLib.AxImageList.get_ListImages.&quot;

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).



Steps to Reproduce Behavior in Visual Basic .NET
 Open a new Windows Control Library project in Visual Basic .NET. Add the ActiveX ImageList control (MSComctl.ocx) to the toolbox. Add an ImageList control (which is listed as ImageControlctrl in the toolbox) to UserControl.  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   Add the following line of code to the constructor of the form, immediately after the InitializeComponent call: IconsSmall = axImageList1.ListImages  Build the project.</li> Add a Visual Basic .NET Windows Application project to the solution. Form1 is created by default.</li> In the toolbox, double-click UserControl1 to add this control to Form1. You receive the error message that is listed in the &quot;Symptoms&quot; section.</li></ol>

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

Keywords: kbbug kbpending kbvs2002sp1sweep kbvs2005swept kbvs2005doesnotapply KB316741

-

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

© Microsoft Corporation. All rights reserved.