-1

Parameter countの不一致例外が発生しました。WindowsForms C#でSystem.Reflection.TargetParameterCountExceptionを解決する方法?

未処理の例外:System.Reflection.TargetParameterCountException:パラメーターの数が一致しません。

METHODINFOベースを呼び出すための私のコードの一部は、私は以下の方法

public string printCustomerDetails(object parameters) 
    { 
     string CustomerName = ""; 
     foreach (object customer in parameters) 
     { 
      CustomerName = CustomerName + " " + customer; 
     } 
     return CustomerName.Trim(); 
    } 

を起動しようとしたとして

Type customerType = executingAssembly.GetType("LateBinding.Customer"); 
     object customerInstance = Activator.CreateInstance(customerType); 
     MethodInfo method = customerType.GetMethod("printCustomerDetails"); 
     string customerObject = (string)method.Invoke(customerInstance, new object[0]); 

を下回っている私はMETHODINFOベースを呼び出すために逃したものはありますか?

+0

を必要としています。 –

+0

オブジェクト宣言を表示してください。 –

+0

@TAHASULTANTEMURIコードを追加しました。 – Arulpriya

答えて

0

Method.Invoke二番目の引数は、配列を必要とするが、コード内部

string customerObject = (string)method.Invoke(customerInstance, new object[0]); 

(新しいオブジェクト[0])。は配列を返しません。printCustomerDetails 配列を返します。

ので、あなたがprintCustomerDetailsメソッドのパラメータをチェックし、同じ数の引数で呼び出す必要

string customerObject = (string)method.Invoke(customerInstance, Details(0));