Select the product you need help with
BUG: Error message when you try to pass a Collection object from Visual Basic 6.0 components to Visual Basic 2005 or to Visual Basic .NET: "System.InvalidCastException"Article ID: 323737 - View products that this article applies to. This article was previously published under Q323737 On This PageSYMPTOMS When you try to pass a Collection object from Microsoft Visual Basic 6.0 components to Microsoft Visual Basic 2005 or to Microsoft Visual Basic .NET, you may receive an error message. In Microsoft Visual Studio 2005, you receive the following error message: An unhandled exception of type 'System.InvalidCastException' occurred in ApplicationName.exe
Additional information: Unable to cast object of type 'Microsoft.VisualBasic.Collection' to type 'VBA.Collection'. An unhandled exception of type 'System.InvalidCastException'
occurred in ApplicationName.exe Additional information: Specified cast is not valid. An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in ApplicationName.exe
Additional information: COM object with CLSID {A4C4671C-499F-101B-BB78-00AA00383CBB} is either not valid or not registered. CAUSEThe InvalidCastException error occurs because the Microsoft.VisualBasic.Collection type is incompatible with the VBA.Collection type. The COMException error occurs because only a Visual Basic 6.0
application can create an instance of the VBA.Collection class. You cannot create an instance of the VBA.Collection class outside a Visual Basic 6.0 application. WORKAROUND To work around this problem, create a VBA.Collection object in a Visual Basic 6.0 application, and then return the object to
the Visual Basic 2005 or Visual Basic .NET application. To do this, you can create a new Visual
Basic 6.0 DLL or add a new method in the existing DLL. Note The index of the Collection object in Visual Basic 2005 or in Visual Basic .NET is base 1. However, the index of Visual Basic 6.0 is base 0. Therefore, you may have to modify the Visual Basic 6.0 DLL to use base 1 as the index for your collection instead of base 0. Create a Visual Basic 6.0 DLL that returns the collection
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. MORE INFORMATIONSteps to reproduce the problem
REFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
316163
(http://support.microsoft.com/kb/316163/
)
Error messages when you attempt to build a Class Library project in Visual Basic .NET or in Visual Basic 2005
PropertiesArticle ID: 323737 - Last Review: February 8, 2007 - Revision: 3.0 APPLIES TO
| Article Translations
|


Back to the top








