如何解决异常“参数计数不匹配”从MethodInfo.Invoke()抛出? [英] How to resolve the exception "Parameter count mismatch" is thrown from MethodInfo.Invoke()?

查看:234
本文介绍了如何解决异常“参数计数不匹配”从MethodInfo.Invoke()抛出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨爵士/女士,

我正在使用网格控件并将数据集绑定到TableAdapter通过设计器视图。当我试图打开"预览和编辑"时窗口更改网格
属性,它会抛出"参数计数不匹配"例外。

堆栈跟踪:

Stack trace:

发生System.Reflection.TargetParameterCountException  HResult = -2147352562 消息=参数计数不匹配。  来源= mscorlib  StackTrace:
        at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj,BindingFlags invokeAttr,Binder binder,Object [] parameters,CultureInfo culture)        at System.Reflection.RuntimeMethodInfo.Invoke(Object
obj,BindingFlags invokeAttr,Binder binder,Object [] parameters,CultureInfo culture)        at System.Reflection.MethodBase.Invoke(Object obj,Object [] parameters)

这里是代码,

MethodInfo mi = cmpType.GetMethod(
    "GetData",
    BindingFlags.Instance | BindingFlags.Public | System.Reflection.BindingFlags.IgnoreReturn | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

if (mi != null)
{
    data = mi.Invoke(component, new object[0]);
}




这里是TableAdapter.GetData()代码,

Public Overridable Overloads Function GetData(ByVal StartDate As Global.System.Nullable(Of Date), ByVal EndDate As Global.System.Nullable(Of Date)) As DataSet1.IW_GETJobsDataTable
    Me.Adapter.SelectCommand = Me.CommandCollection(0)
    If (StartDate.HasValue = True) Then
        Me.Adapter.SelectCommand.Parameters(1).Value = CType(StartDate.Value, Date)
    Else
        Me.Adapter.SelectCommand.Parameters(1).Value = Global.System.DBNull.Value
    End If
' additional implemented code here
   Me.Adapter.Fill(dataTable)
   Return dataTable
End Function




< span style ="font-si ZE:宋体; font-family:Verdana,sans-serif">请帮我解决这个问题,让我知道这个问题的原因。

谢谢,

Mohanraj

Mohanraj G

Mohanraj G

推荐答案

即使参数是可省略的,当通过.Invoke()调用时,你还需要

匹配参数计数
,用
Missing.Value





Even if the parameter is omittable, when calling through .Invoke() you'd still need to match the parameter count by filling that with Missing.Value.



这篇关于如何解决异常“参数计数不匹配”从MethodInfo.Invoke()抛出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆