C
C#7mo 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
Jimmacle7mo ago
delegates for instance methods need a reference to the instance they should be called on
SleepWellPupper
SleepWellPupper7mo ago
Looks like you'd want to use this overload instead.
Althos
AlthosOP7mo ago
Thanks, I was indeed using the wrong overload, thanks for the info too !
Want results from more Discord servers?
Add your server