Skip to content

Exception "Incorrect number of arguments supplied" when params array has null in first parameter #263

@stefanoIT

Description

@stefanoIT

Hello Davide and everyone.

Consider this function

public static class ParamArrayTester
{
  public static int ParamArrayObjects(params object[] values)
  {
    return values.Length;
  }
}

If I implement the following test:

[Test]
public void Test_ParamArrayObjects()
{
  Interpreter dexp = new Interpreter();
  
  dexp.Reference(typeof(ParamArrayTester));
  string expText = "ParamArrayTester.ParamArrayObjects(null, null, 0, 0)";
  Object resultObject = dexp.Eval(expText);
  
  Assert.AreEqual(4, (int)resultObject);
}

Exception :

System.ArgumentException: 'Incorrect number of arguments supplied for call to method 'Int32 ParamArrayObjects(System.Object[])' (Parameter 'method')'

On Stack:

ParseNormalMethodInvocation
return Expression.Call(instance, (MethodInfo)method.MethodBase, method.PromotedParameters);

The following call works perfectly :

string expText = "ParamArrayTester.ParamArrayObjects(0, null, null, null)";

So the guess is that the first parameter makes the difference somehow.

Thanks in advance, cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions