System.Reflection.TargetParameterCountExeception:参数计数不匹配

时间:2013-10-08 11:33:33

标签: c#

System.Resources.ResourceManager ResManager
    = new System.Resources.ResourceManager(
        "derp",
        System.Reflection.Assembly.GetExecutingAssembly());

byte[] cmBytes
    = System.Convert.FromBase64String((string)ResManager.GetObject("cFile"));

/*BinaryWriter bw1
      = new BinaryWriter(new FileStream("test.exe", FileMode.Create));
  bw1.Write(cmBytes);
  bw1.Flush();
  bw1.Close();*/

Assembly asm = Assembly.Load(cmBytes);
MethodInfo mi = asm.EntryPoint;
object go = asm.CreateInstance(mi.Name);
mi.Invoke(go, null);

错误指向mi.Invoke(go, null),我在这里难倒。

1 个答案:

答案 0 :(得分:0)

在这种情况下,入口点采用参数 - 正如异常所暗示的那样(可能是字符串列表),所以显然你不能在没有参数的情况下调用它(null作为第二个参数)。尝试:

mi.Invoke(go, new object[] { new string[0] } );

请注意,这当然仅适用于具有接受字符串列表的入口点的程序集。根据要运行的程序集的类型,您可能需要为此添加更多逻辑。你也可以在程序集中拥有static void Main(),这样你的版本就可以了。

相关问题