I create a c# dynamic object of a COM-Object on the fallowing way:
dynamic pdfCreator = Activator.CreateInstance(
Type.GetTypeFromProgID("PDFCreator.clsPDFCreator"));
The class clsPDFCreator is defining an event calling eReady. But when I try to register an Eventhandler like
pdfCreator.eReady += _PDFCreator_eReady;
I get the error message "Operator '+=' cannot be applied to operands of type 'dynamic' and 'method group'".
How can i register an EventHandler to an Event which is declared of a dynamic object?
Since the delegate type is not known at compile time, you have to specify it. The Action
delegate matches methods with no parameters or return value:
pdfCreator.eReady += new Action(_PDFCreator_eReady);
How about this:
public delegate void eReadyHandler();
static void Main(string[] args)
{
var comType = Type.GetTypeFromProgID("PDFCreator.clsPDFCreator");
dynamic pdfCreator = Activator.CreateInstance(comType);
//dynamic pdfCreator = new PDFCreator.clsPDFCreator();
//pdfCreator.eReady = null;
pdfCreator.eReady += new eReadyHandler(_PDFCreator_eReady);
}
public static void _PDFCreator_eReady()
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With