BUG: Error at run time after you upgrade a Microsoft Visual Basic 6.0 project that uses the ImageList control to Microsoft Visual Basic .NET (814314)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2002)

SYMPTOMS

When you upgrade a Microsoft Visual Basic 6.0 project that uses the ImageList control to a Microsoft Visual Basic .NET project by using the Microsoft Visual Basic .NET Upgrade Wizard, you receive the following exception when you run the project in Visual Basic .NET:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in axinterop.mscomctllib.dll

CAUSE

The Visual Basic .NET Upgrade Wizard wraps the ImageList control in the AxHost class. However, it does not modify the corresponding Visual Basic 6.0 code to access the underlying ImageList control. For example, the following code may be part of the migrated Visual Basic .NET code.
ListView1.ColumnHeaderIcons = ImageList

WORKAROUND

To work around this problem, assign the underlying ImageList control instead of the wrapper control. You can access the underlying ImageList control by using the GetOcx method. To do this, locate the following code in the migrated Visual Basic .NET code:
ListView1.ColumnHeaderIcons = ImageList
Replace the existing code with the following code:
ListView1.ColumnHeaderIcons = ImageList.GetOcx

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual Basic .NET (2003).

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Visual Basic 6.0 Standard EXE project.

    By default, Form1 is created.
  2. On the toolbox, click Components.
  3. Click the Controls tab, click to select the Microsoft Windows Common Controls 6.0 component, and then double-click on the selected item. Click OK.
  4. On the toolbox, double-click the ImageList control.
  5. On the toolbox, double-click the ListView control.
  6. Right-click the ImageList control, and then click Properties.
  7. Click the Images tab, and then add pictures in the ImageList.
  8. Add the following code to the Form_Load function in the code editor:
    Private Sub Form_Load()
            Dim mItem As ListItem
            Dim cItem As ColumnHeader
            ListView1.ColumnHeaderIcons = ImageList1
            ListView1.ListItems.Clear
            ListView1.View = lvwReport
            Set mItem = ListView1.ListItems.Add(1, , "hola")
            Set cItem = ListView1.ColumnHeaders.Add(, , "Header")
            cItem.Icon = 2
    End Sub
  9. On the File menu, click Save. Close Visual Basic 6.0.
  10. Open Visual Studio .NET IDE.
  11. On the File menu, click Open, and then click Project.
  12. Click to select the Visual Basic 6.0 project that you created.

    Upgrade Wizard is started.
  13. Follow the instructions to upgrade the project to Visual Basic .NET (2002).
  14. On the Debug menu, click Start to run the application.

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

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

317885 HOW TO: Use the Visual Basic Upgrade Wizard



Modification Type:MajorLast Reviewed:3/20/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbinterop kbImgList kbMigration kbmigrate kbWindowsForms kbForms kbfix KB814314 kbAudDeveloper