Heybo Blog

If you look at me when I'm talking, you'll see what I'm saying ... about Tech and .NET discoveries!

My Links

News

Story Categories

Archives

Post Categories

Image Galleries

Login

Blog Stats

Links

Personal Websites

COM object with CLSID ... is either not valid or not registered.

SYMPTOMS

When you try to pass a Collection object from Microsoft Visual Basic .NET to Visual Basic 6.0 components, you may 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 .NET expects, you find that the VBA.Collection type is expected instead of the Microsoft.VisualBasic.Collection type. If you change your code to pass a collection object of the type VBA.Collection, 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# .NET.

CAUSE

The InvalidCastException occurs because Microsoft.VisualBasic.Collection is not compatible with VBA.Collection. You receive COMException error because VBA.Collection is designed in such a way that only a Visual Basic 6.0 application can create an instance of the VBA.Collection class. You cannot create an instance of VBA.Collection outside a Visual Basic 6.0 application.

WORKAROUND

To work around this issue, create a VBA.Collection object in a Visual Basic 6.0 application, and then return it to the 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 .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 1 as the base index for your collection instead of 0.

 

source

posted on Thursday, January 22, 2004 6:08 AM

Feedback

# re: COM object with CLSID ... is either not valid or not registered. 8/16/2005 3:32 PM CMP

How do you modify the Visual Basic 6.0 DLL to use 1 as the base index instead of 0.

Title  
Name  
Url
Comments   
Protected by Clearscreen.SharpHIPEnter the code you see: