calling a delegate in a late bound C# dll

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

How do I call a delegate in late bound C# dll? there some way to do this w/
a sharedinterface file? any examples? i tried this but it doesnt work:

(oType.GetMethod("IOCTLJOB").Invoke(pObj, new object[] {
pClass1.m_job } )).ToString();

and it returns the error:

Additional information: Object type cannot be converted to target type.

I have the delegate defined in both the late bound dll and the host assembly
like this:
public delegate void Job();
 
Daniel,
A delegate is not a method so GetMethod does will not work. In the
late bound dll what is IOCTLJOB? Where did you get oType from? Show
some code from both dll's and I can probably help you. From your
question I am still not sure what you are trying to accomplish.

PS if you need to have a void delegate with no args then the framwork
defines MethodInvoker so no need to create your own class.
Cecil Howell MCSD, MCAD.Net, MCT
 
Here's one way to do it:

protected void PerformAction(string delegateMethodName)
{
MyDelegate targetAction = Delegate.CreateDelegate(typeof(MyDelegate), this,
delegateMethodName) as MyDelegate;
...
}

((MyDelegate)(targetAction.Method)).Invoke(this, new object[] {
myParameter } );


I didn't actually compile the code, but it should be pretty close.

Hope that helps.
 
Back
Top