I am trying to add a delegate to an EventHandler in word but keep getting an Argument Exception while using the below code:
Type ty = this.Aplication.GetType().GetEvent("DocumentBeforeClose").EventHandlerType;
this.Application.GetType().GetEvent("DocumentBeforeClose").AddEventHandler(this,Delegate.CreateDelegate(ty, this, "test",false));
test just pops up a messagebox.
Does anyone know why this is happening.
Can’t test code right now, but what if use
See this.Application instead of this in AddEventHandler call.
UPDATE:
Now I can test the code and it works fine without exceptions if change “this” to “this.Application” as I mentioned before. Here is a full code:
So ensure, that your “test” method has a valid signature. Also ensure, that “test” is the exact method name, not “Test” or something.