4

I am trying to return an array from c# to classic asp using com. This post helped me lot, but I still have problems:

I have the following method in c#:

public object[] returnStuff () {
    return new object[] {'1','2','3'};
}

My classic ASP:

dim responseArray1

responseArray1 = RegusSoapComponent.returnStuff()

response.write("Type of Array one is " & VarType(responseArray1))
response.write("Type of Array one is " & responseArray1(1))

My output is:

response is Type of Array one is 8204

Microsoft VBScript runtime error '800a01ca'

Variable uses an Automation type not supported in VBScript

No matter what I do, I don't seem to be able to access this variable.

5
  • Try return new object[3] {'1','2','3'}; ? Commented Jul 4, 2011 at 16:55
  • @Gage: That won't make any difference at runtime. Commented Jul 4, 2011 at 16:56
  • @SLaks, I don't think it will either but thats the only difference I see between his and the example he posted. Commented Jul 4, 2011 at 18:13
  • @IKode "The Array function, on the other hand, always creates an array of Variants-VarType 8204 (which is 8192 plus 12)." Taken from this page brainbell.com/tutors/Visual_Basic/Arrays.htm. So you are creating an array of variants. Whats the length of the array returned? Commented Jul 4, 2011 at 18:22
  • 1
    What if you try to return array of strings? return new object[] {"1", "2", "3"}; maybe for some reason char type is causing problems.. Commented Jul 5, 2011 at 7:36

1 Answer 1

5

VBScript likes to receive a variant containing a safearray of variants. So you need to return an object wrapping your array of objects. eg:

public object returnStuff() {
    return new object[] {'1','2','3'};
}

which should get marshalled the right way. See a previous answer for the detailed version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.