“Object does not match target type” error calling a method on an assembly loaded using reflection
By rickvdbosch
- 1 minutes read - 149 wordsActually, the cause for this error is very small and simple. But because the error doesn’t clearly state what’s wrong and there’s not a lot to be found about this, I’ll post it here anyway… Otherwise, you might be looking for this for a while, while it’s so easy!
When you are loading an assembly using reflection and you want to call a method from the class that’s in the loaded assembly, you might get the error Object does not match target type
. Even when the method is void and takes no parameters this error can occur. In that case: make sure the methods in the assembly you loaded are static.
Yes, I did have this error myself and yes, I found out the static-part myself eventually. But it took me half an hour. Let’s just say it was at the end of a very, very long day….. 😉