加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:16:44 所属栏目:百科 来源:网络整理
导读:我需要为我的经典asp创建一个com对象,因为我可以创建一个.net程序集并将它与’interop’一起使用,所以我继续创建一个像这样的.net程序集: – using System;using System.Collections.Generic;using System.Runtime.InteropServices;using System.Linq;using
我需要为我的经典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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读