Classic 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()