我想传递一个整数数组从经典ASP到在C#中创建的DLL。如何将传统asp的整数数组传递给c#COM对象?
我有下面的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()
由于int []被Com Interop作为SAFEARRAY编组,所以它基本上是以下副本:http://stackoverflow.com/questions/5910538/how-to-create-a-safearray-in-windows-jscript –
如果它是重复的,那么我不明白它,因为我不知道如何采取答案,使我的代码工作 – Graham