❔ Building a delegate with a Type and a MethodInfo keeps throwing ArgumentException
Hi ! I'm trying to build a delegate from a Type and a MethodInfo. The type correspond to the method 1st argument's type. I have the following code :
Unfortunately, the function throws an exception every time I call it, saying method arguments are incompatible.
The signature of the method I'm using to test it is the following one :
void LogInConsole(BaseClass item)
.
I'm calling CreateRemoveMethod like this : CreateRemoveMethod(typeof(BaseClass), methodInfo)
, with methodInfo corresponding LogInConsole that I gathered through reflection.
Would you have any insight on what I'm doing wrong here ? 🙂13 Replies
Everything looks fine, could you paste the full exception here?
This is my test scenario of yours that i copied and everything works fine
The comments are things you can do to make it neater or more easy with less method calls.
I've even tried a more complex type like Func<string> as the first parameter to test and that works too
I didn't make the method generic because I won't know the element type in every scenario. But here is the full exception
I've converted the method to be this instead to fit your situation more
everything still runs fine, I've even created a makeshift scenario of class inheritance to act as your base class.
By any chance are you executing that within the context of an Il2Cpp unity game?
If you are passing through an Il2Cpp type that may cause some exceptions
Yes, it's within unity for editor code
I suspected it could be linked to this
That's bothersome
Is your unity game built to target il2cpp? or is it just normal mono?
Well, since it's code to modify the editor behaviour, I'll suppose it depends on what unity is running on
It's not like a game which I could decide if it's il2cpp or mono unfortunately 😦
But thanks to you I know that it's a unity issue now and apparently the method needs to be a static method
hmm, if it wasnt a static, you'd need to provide an instance
as the first parameter
Yes
then normal parameters following
And I think that's what I was missing
could very well be that
That was the issue, i was missing the instance. Thanks for the help 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.