Ok, this is pretty niche, but I'm hoping someone out there can help me. Also, I'm comfortable in CSharp, but am inexperienced in JScript and COM.
The problem is this. I'm supporting an application component written in CSharp and exposed as a COM object. It exposes several public methods, which are invoked by it's client applications. The clients are all classic ASP script files written in JScript. I'd like to add a new public method to the COM object which returns a collection of objects.
First, returning a single result object works fine...
I'm able to return a single object and access it's properties. For example, in this C# signature...
ResultObject GetResult();
...ResultObject is a POCO with simple properties and no logic. I'm able to access it's properties with the following JScript:
var oMyObject = Server.CreateObject("MyNamespace.MyObject");
var result = oMyObject.GetResult();
Response.Write("<br /><i>('" + result.Value + "', '" + result.ID + "')</i>");
However, it breaks when I return an array...
When I try and return a simple array of ResultObjects from C#...
ResultObject[] GetResults();
...and access it from JScript...
var oMyObject = Server.CreateObject("MyNamespace.MyObject");
var results = oMyObject.GetResults();
for (var i = 0; i < results.length; i++) {
Response.Write("<br /><i>('" + results[i].Value + "', '" + results[i].ID + "')</i>");
}
...I get the following error when invoking the script:
Microsoft JScript runtime error '800a138f'
'results.length' is null or not an object
Additionally, trying a JScript "typeof results" give me a type of "unknown".
How can I return a collection (array, IEnumerable, etc.) from a CSharp class exposed as a COM object and access it from classic ASP JScript?