我正在尝试将整数数组从经典 ASP 传递到用 C# 创建的 DLL。
我有以下 C# 方法:
public int passIntArray(object arr)
{
int[] ia = (int[])arr;
int sum = 0;
for (int i = 0; i < ia.Length; i++)
sum += ia[i];
return sum;
}
我尝试了多种方法将 arr 转换为 int[],但没有任何成功。我的asp代码是:
var arr = [1,2,3,4,5,6];
var x = Server.CreateObject("dllTest.test");
Response.Write(x.passIntArray(arr));
我目前收到以下错误:
Unable to cast COM object of type 'System.__ComObject' to class type 'System.Int32[]'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
谁能告诉我怎么做或告诉我不能做?
使用这个非常有用的页面http://www.add-in-express.com/creating-addins-blog/2011/12/20/type-name-system-comobject/上的代码我设法发现如果有用的话,传递参数的类型是“JScriptTypeInfo”。
如果我添加:
foreach (object m in arr.GetType().GetMembers())
// output m
我得到以下输出:
System.Object GetLifetimeService()
System.Object InitializeLifetimeService()
System.Runtime.Remoting.ObjRef CreateObjRef(System.Type)
System.String ToString()
Boolean Equals(System.Object)
Int32 GetHashCode()
System.Type GetType()