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?