Say I've a class like this inside a class library project called SomeClass-
Public Class SomeClass
Public Function DoIt() as String
Return "Do What?"
End Function
End Class
I get a SomeClass.dll
which I want to load at runtime from another Windows Forms Application, and then have it call the DoIt()
function and show it's value in a messagebox or something. How do I do that?
I suggest to make
DoIt
shared, since it does not require class state:Then calling it is easy:
If you cannot make the method shared, you can create an instance of your class with Activator.CreateInstance and pass it as a parameter to Type.InvokeMember.
All my code examples assume Option Strict On and Option Infer On.