![](/img/trans.png)
[英]How do I pass an array of integers from classic asp to a c# COM object?
[英]COM Interop (how to pass an array to the com) via classic ASP
我需要为我的经典 asp 创建一个 com 对象,因为我可以创建一个 .net 程序集并让它与 com“互操作”,所以我继续创建一个这样的 .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)
我得到错误:
错误类型:Microsoft VBScript 运行时 (0x800A0005) 无效的过程调用或参数:“添加”/eduservice/test.asp,第 25 行
但是,如果我修改程序集不使用数组,这一切都可以正常工作,我什至可以将普通字符串或 int 发送到程序集和从程序集发送到经典 asp。 我读了很多东西,但我得到了同样的错误,
以前有人尝试过并且成功了,请分享您的解决方案
谢谢
ASP 只能处理变体数组,而不是字符串或整数数组。 所以尝试使用一个对象,例如,
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.