-1

I'm getting the Parameter count mismatch exception.

Unhandled Exception: System.Reflection.TargetParameterCountException: Parameter count mismatch.

My code part for invoking the MethodInfo base is as below

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]);

I have tried to invoke the below method

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

Is there anything I missed to invoke MethodInfo base?

James Z
  • 12,209
  • 10
  • 24
  • 44
Arulpriya
  • 173
  • 10

1 Answers1

0

Method.Invoke second argument require an array but inside your code

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

The (new object[0]); is not returning array.Its printCustomerDetails which return an array.

so you need

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