C
C#2mo ago
Althos

Delegate.CreateDelegate returns "ArgumentException: method arguments are incompatible"

Any idea what I did wrong here ? My method seems to be of the correct type
public void RegenerateEventEnums()
{
FieldInfo[] fields = typeof(Card).GetFields();
foreach (FieldInfo field in fields)
{
var del = Delegate.CreateDelegate(typeof(Action<Card>), GetType().GetMethod("Test"));
}
}

public void Test(Card card)
{
Debug.Log("My card!");
}
public void RegenerateEventEnums()
{
FieldInfo[] fields = typeof(Card).GetFields();
foreach (FieldInfo field in fields)
{
var del = Delegate.CreateDelegate(typeof(Action<Card>), GetType().GetMethod("Test"));
}
}

public void Test(Card card)
{
Debug.Log("My card!");
}
4 Replies
Jimmacle
Jimmacle2mo ago
delegates for instance methods need a reference to the instance they should be called on
SleepWellPupper
SleepWellPupper2mo ago
Looks like you'd want to use this overload instead.
Althos
Althos2mo ago
Thanks, I was indeed using the wrong overload, thanks for the info too !