6

I need to create a com object for my classic asp, since i can create a .net Assembly and have it 'Interop' with com, so i proceeded to create a .net Assembly like this:-

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web;


namespace LMS
{

[ComVisible(true)]
public class Calc
{

    public int Add(int val1, int val2, out string[] outputz)
    {
        int total = val1 + val2;
        outputz = new string[5];
        outputz[1] = "test2";
        outputz[2] = "test3";
        outputz[3] = "test4";
        outputz[4] = "test5";
        return total;
    }


}
}

Next i did the usual, build, ran: gacutil & RegAsm

and in my classic asp page i had this:-

Dim params  
dim objPassport3
set objPassport3 = Server.CreateObject("LMS.Calc")
comTest2 = objPassport3.Add(1,1,params)

and i get error:

Error Type: Microsoft VBScript runtime (0x800A0005) Invalid procedure call or argument: 'Add' /eduservice/test.asp, line 25

But if i modify the assembly not to use an array, it all just work, i can even send normal string or int to and from the assembly to classic asp. i read so many things but i get the same error,

anyone tried this before and was successful, please do share your solution

thanks

1 Answer 1

10

ASP can only handle arrays that are variant, rather than arrays of strings or ints. So try using an object instead, e.g.,

public int Add(int val1, int val2, out object outputz)
{
    int total = val1 + val2;
    outputz = new object[5]
      {
          "test1",
          "test2",
          "test3",
          "test4",
          "test5"
      };

    return total;
}
Sign up to request clarification or add additional context in comments.

3 Comments

thanks so much for the reply...cant wait to try..will update you on the status
OrbMan, thanks, you solved my problem, wish i could treat you for lunch.
This is the same for VBScript. Even though you can CreateObject complex types exposed through COM from VBScript, you cannot pass them back into a method from a .NET assembly unless the complex parameters of that method are of type object. Primitives (e.g., string, int, etc.) are fine.

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.