Problem passing Collection from VB.Net to VB6



I have run the VB.Net upgrade wizard to get a vb6 project up to VB.Net
1.1. This is a class library that is referenced by another VB6 app. I
have exposed it to for COM access. The problem is that the collection
object that is being passed from VB.Net to VB6 is giving me a "type
mismatch" error when assigned to a collection variable in vb6. The
collection in VB.Net is Microsoft.VisualBasic.Collection, so I do not
see why this is causing any trouble at all. Here is some example code
that causes the problem mentioned:

VB.Net Class:
ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)> _
Public Class Class1

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String =
Public Const InterfaceId As String =
Public Const EventsId As String =
#End Region

Public Function GetCollection() As Microsoft.VisualBasic.Collection
Dim c As New Collection
Return c
End Function

End Class

VB6 Code that references it (with proper reference added in
'references' of course)
Private Sub Command1_Click()
Dim c As Collection
Dim myClass As New ClassLibrary1.Class1
Set c = myClass.GetCollection 'THIS LINES CAUSES "TYPE MISMATCH"
End Sub

Any thoughts on why this error is occuring? How can I pass a
Microsoft.VisualBasic.Collection from .Net to vb6?

Thanks for any suggestions.


Cor Ligthert [MVP]


The only class that most regulars or others find it a pity that it is in the
VB namespace and not in the compatilbe namespace (which is temporaly) is the
vb.collection. It gives you only trouble.

Try to change it as soon as possible for a Net List or Collection class as
soon as possible.

As most things which have synonyms it is now almost impossible to find on
MSDN. You have first to strugle through things as foxpro etc. But try it.
Keywords to search are Ilist ICollection "Collection Class" "List Class"
"Generic list"

I hope this helps,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question