1

I'm getting this error (translated from german): An exception (first chance) from the Type "System.Reflection.TargetParameterCountException" occured in System.Windows.Forms.dll.

My Code:

        private async void ClientLogedIn(object sender, string username, string ipAddress)
    {
        PVPNetConnect.RiotObjects.Platform.Clientfacade.Domain.LoginDataPacket LoginData = await pvp.GetLoginDataPacketForUser();
        PVPNetConnect.RiotObjects.Platform.Summoner.AllSummonerData AllSummonerData = LoginData.AllSummonerData;
        PVPNetConnect.RiotObjects.Platform.Summoner.Summoner Summoner = AllSummonerData.Summoner;
        Invoke(new AddDelegate(Add), new string[] { "Dd", "ee", "ff" });
    }

The delegate + void:

        private delegate void AddDelegate(String[] vars);
    private void Add(string[] vars)
    {
        var li = new ListViewItem(vars);
        listView1.Items.Add(li);
    }

2 Answers 2

3

You need to wrap the array into the first element of an object array:

Invoke(new AddDelegate(Add), new object[] { new string[] { "Dd", "ee", "ff" } });

Note that this is typically easier to write using a lambda instead, as you don't need to worry about the delegate declaration or managing the object array:

Invoke(new Action( () => Add(new[] { "Dd", "ee", "ff" }));
Sign up to request clarification or add additional context in comments.

Comments

1

Because Invoke uses params for the second argument, you can either provide N different arguments and have them all wrapped up in an array for you, or you can just provide an array of all of the arguments to pass in. Here your string array is interpreted as meaning "pass in three arguments, each of type string", which is not what you want, you want to pass in one argument of type string[]. To do this simply ensure that the compile time type of the argument isn't an array, this can be done with a simple cast:

Invoke(new AddDelegate(Add), (object)new string[] { "Dd", "ee", "ff" });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.