C # collection for classic ASP

I'm having trouble displaying a C # collection for classic ASP. I tried using IEnumerable and Array. but I get the error " object not a collection ".

my method is as follows:

 public IEnumerable<MyObj> GetMyObj() { ... } 

and on the side of classic ASP:

 Dim obj, x Set obj = Server.CreateObject("Namespace.class") For Each x in obj.GetMyObj ... 

So how can I transfer a collection to Classic ASP?

UPDATE:

maybe this is progress, the solution I found is to use a new class that inherits IEnumerable instead of using IEnumerable<MyObj> :

 public class MyEnumerable : IEnumerable { private IEnumerable<MyObj> _myObj; . . . [DispId(-4)] public IEnumerator GetEnumerator() { _myObj.GetEnumerator(); } } 

But now, when I try to access the MyObj property , I get the error message: Object required .

Any idea?

+7
collections c # asp-classic com
source share
4 answers

I think you have found the answer; Classic ASP with VB does not have generics built into it. So, you are trying to pass IEnumerable<MyObj> to ASP, and it comes out like a nightmare name mashup, in which the classic ASP has no idea how to work.

The solution is to pass a non-generic IEnumerable. The problem is that the sequence is treated as containing the base object instances. You should return to the pre-2.0 methods for retrieving the objects you selected from the list. In VB, this is not complicated; I’ll just explicitly indicate the type of element, and VB will implicitly quit for you, iterating through β€œFor Everyone”:

 Dim obj, x Set obj = Server.CreateObject("Namespace.class") For Each x As MyObj in obj.GetMyObj //casts each element in turn ... 
+6
source share

I know this may seem strange, but I had a similar problem, and I decided to wrap it around the collection with brackets

 For Each x in (obj).GetMyObj 

I don't know why this matters, but it worked for me ...

0
source share

If you get an Object required error, try this:

 For Each key in obj.GetMyObj Set x = obj.GetMyObj(key) Response.Write x.YOURPROPERTY Next 
0
source share

Reversing technique can solve the problem. Try passing the ASP classic collection to ASP.NET, and then see what an object type is. You can then pass this type from ASP.NET to classic ASP instead of the trial error method. If ASP.NET does not have the appropriate type, you should do more reverse engineering and examine binary data to find a pattern and write your own casting method.

0
source share

All Articles