c# – COM Interop(如何通过经典ASP将数组传递给com)

我需要为我的经典asp创建一个com对象,因为我可以创建一个.net程序集并将它与’interop’一起使用,所以我继续创建一个像这样的.net程序集: –
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;
    }


}
}

接下来,我做了通常的,构建,运行:gacutil& RegAsm

在我的经典asp页面我有这个: –

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

我得到错误

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

但是,如果我修改程序集不使用数组,它只是工作,我甚至可以将正常的字符串或int发送到程序集和从程序集到经典的asp.
我读了很多东西,但我得到了同样的错误,

有人试过这个并且成功了,请分享你的解决方

谢谢

解决方法

ASP只能处理变量的数组,而不是字符串或整数的数组.所以尝试使用对象,例如,
public int Add(int val1,out object outputz)
{
    int total = val1 + val2;
    outputz = new object[5]
      {
          "test1","test2","test3","test4","test5"
      };

    return total;
}

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...