【问题标题】:COM Interop (how to pass an array to the com) via classic ASPCOM Interop(如何将数组传递给 com)通过经典 ASP
【发布时间】:2009-08-31 10:04:18
【问题描述】:

我需要为我的经典 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。 我读了很多东西,但我得到了同样的错误,

任何人都试过这个并且成功了,请分享你的解决方案

谢谢

【问题讨论】:

    标签: c# .net asp-classic com-interop


    【解决方案1】:

    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;
    }
    

    【讨论】:

    • 非常感谢您的回复...迫不及待想尝试..将更新您的状态
    • OrbMan,谢谢,你解决了我的问题,希望我能请你吃午饭。
    • 这与 VBScript 相同。即使您可以CreateObject 从 VBScript 通过 COM 公开的复杂类型,也不能将它们从 .NET 程序集传递回方法,除非该方法的复杂参数是对象类型。原语(例如,字符串、整数等)很好。
    猜你喜欢
    • 2010-11-01
    • 2014-09-12
    • 2011-09-18
    • 2012-05-15
    • 2012-09-06
    • 2011-01-02
    • 2011-08-04
    • 2012-07-13
    • 2011-09-29
    相关资源
    最近更新 更多