Symptoms
When you try to pass a Collection object fromMicrosoft 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’.In Microsoft Visual Studio .NET, you receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in ApplicationName.exe
Additional information: Specified cast is not valid.If you examine the type of the collection object that Visual Basic 2005 or Visual Basic .NET expects, you find that Visual Basic 2005 or Visual Basic .NET expects the VBA.Collection type instead of the Microsoft.VisualBasic.Collection type. If you change your code to pass a collection object of the VBA.Collection type, you receive the following error message on the line of code where you try to create a new instance of the VBA.Collection class:

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.This problem also occurs in other Microsoft .NET Framework-supported languages such as Microsoft Visual C# 2005 and earlier versions of .NET Framework-supported Microsoft Visual C#.
Resolution
The 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.