This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
Original Post: Why do delegate arguments have to match exactly?
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
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.