Why do delegate arguments have to match exactly, when creating a delegate using Delegate.CreateDelegate?
delegate void SpecialEventHandler(object sender, SpecialEventArgs e);
void SpecialMethod(object sender, EventArgs e)
Now the following
Delegate.CreateDelegate(typeof(SpecialEventHandler), o, SpecialMethod)
fails, even though EventArgs is a direct parent of SpecialEventArgs. Shouldn't it be possible to use (safe downcast?) this method as a delegate target?
This is an interesting question. It should be possible to be able to support this, but we don't support it currently. IIRC, there's a runtime rule that says that a delegate must match exactly. The fancy name for this is delegate contravariance.
This could be something that we support in the future.