Skip to content

MethodInvoker synthesizes arguments not provided? #90039

Closed
@stephentoub

Description

@stephentoub

I was expecting this to throw an exception:

using System.Reflection;

internal class Program
{
    private static void Main()
    {
        var invoker = MethodInvoker.Create(typeof(Program).GetMethod("MyMethod", BindingFlags.NonPublic | BindingFlags.Static)!);
        invoker.Invoke(null);
    }

    static void MyMethod(int arg0, int arg1, int arg2) => Console.WriteLine($"{arg0} {arg1} {arg2}");
}

since the method has three non-optional parameters and zero arguments are being supplied, but instead it printed:

0 0 0

Is that by design?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions