Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#/vb.net类型不匹配通过反射查找构造函数(Integer()与System.Int32[])_C#_Vb.net_Reflection_Interop_Constructor - Fatal编程技术网

C#/vb.net类型不匹配通过反射查找构造函数(Integer()与System.Int32[])

C#/vb.net类型不匹配通过反射查找构造函数(Integer()与System.Int32[]),c#,vb.net,reflection,interop,constructor,C#,Vb.net,Reflection,Interop,Constructor,我正在将C代码中的类型名和一些参数传递到用VB编写的导航框架中。导航框架在类型上查找与使用type.GetConstructor(Types())传入的参数匹配的构造函数。我正在寻找的构造函数需要一个整数数组——vb中的Integer()。但是它得到一个System.Int32数组。我甚至尝试过这个: System.Int32[] int32Array = IdList.ToArray(); int[] intArray = new int[int3

我正在将C代码中的类型名和一些参数传递到用VB编写的导航框架中。导航框架在类型上查找与使用type.GetConstructor(Types())传入的参数匹配的构造函数。我正在寻找的构造函数需要一个整数数组——vb中的Integer()。但是它得到一个System.Int32数组。我甚至尝试过这个:

           System.Int32[] int32Array = IdList.ToArray();
            int[] intArray = new int[int32Array.Length];
            for (int i = 0; i < int32Array.Length; i++ )
            {
                intArray[i] = (int)int32Array[i];
            }
System.Int32[]int32Array=IdList.ToArray();
int[]intArray=new int[int32Array.Length];
for(inti=0;i
VB代码仍然在另一端看到System.Int32,这意味着它找不到构造函数

有什么见解吗?

因为C#
int
系统的合成糖。Int32
,VB
Integer
也是同一类型的合成糖。所以打电话给他们应该没什么问题


但是,我会检查
GetConstructor
方法返回的构造函数信息的参数类型。

我想猜测一下,您犯的错误与我犯过几次的错误相同

当您调用并构建一个类型数组时,我有时会生成一个类型对象数组,数组中的每个元素对应一个

让我解释一下

我有一个整数数组(System.Int32),我想找到一个构造函数,它接受一个参数,这个参数就是这样一个整数数组

现在,在C#中,生成可传递给GetConstructor的类型数组的正确方法如下:

Type[] types = new Type[] { typeof(Int32[]) };
Type[] types = (from v in arr select v.GetType()).ToArray();
相反,我在一些情况下编写了如下代码:

Type[] types = new Type[] { typeof(Int32[]) };
Type[] types = (from v in arr select v.GetType()).ToArray();
这是一个愚蠢的错误,但此更改使GetConstructor查找具有与数组中的值相同数量的参数的构造函数

也许你也做过同样的事

因为您并没有实际向我们展示调用反射的代码,所以这只是猜测