I'm trying to pass an array of integers from Classic ASP to a DLL created in C#.
I have the following C# method:
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;
}
I've tried a number of ways to convert arr to an int[], but not having any success. My asp code is:
var arr = [1,2,3,4,5,6];
var x = Server.CreateObject("dllTest.test");
Response.Write(x.passIntArray(arr));
I am currently getting the following error:
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.
Can anyone tell me how to do it or tell me it can't be done?
Using the code on this very useful page http://www.add-in-express.com/creating-addins-blog/2011/12/20/type-name-system-comobject/ I have managed to find out that the type of the passed parameter is "JScriptTypeInfo" if that's of any use.
If I add:
foreach (object m in arr.GetType().GetMembers())
// output m
I get the following output:
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()