0
votes

I need to author a .NET assembly that is visible as a COM object through COM Interop, such that it can supply a collection to a VBScript or JScript program.

When I use simple collections such as ArrayList, that flows through COM interop and can be iterated over in VBScript using a program like this:

Dim s, foo
Set foo = CreateObject("Whatever.Collection")
For Each s In foo
    WScript.Echo s
Next

Now, if instead of ArrayList I use somethign based on a generic collection class, such as List<string>, or System.Collections.Specialized.StringCollection, that doesn't seem to work in the VBScript. I get errors in the For Each loop, like

Microsoft VBScript runtime error: Object required:

So, it seems like there is some magic sauce that I'm missing here somewhere. What does it take to make a .NET collection flow through COM Interop and work correctly in VBScript and JScript?

1
As far as I know generics aren't supported in interop. - sarvesh

1 Answers

1
votes

I started looking to see if there is a solution to this since I didn't think it was possible. It seems like Rick Strahl has a solution.

Edit: Here is another solution on SO What are alternatives to generic collections for COM Interop?