我想傳遞一個整數數組從經典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