See Roslyn: Convert delegate types with compatible signature automatically
Currently the various CLR compilers do not permit treating one delegate of a specific signature as the same as another delegate of an identical signature. The compilers that do (VB.NET) do so by wrapping the existing delegate instance with the new delegate which incurs a performance penalty at the time of invocation.
It appears that for whatever reason, accidentally or otherwise, the CLR/JIT have no real issue using one delegate in place of another. The verifier does complain that an unexpected type is on the stack for the specified call but otherwise the program does execute.
I propose that the verifier be modified that if the type expected and the type on the stack are different but are both delegate types, and that the Invoke method on both delegates share the same signature that the verifier allow the operation.
This would permit delegates of identical signatures to be considered equivalent without the performance penalty either at the time of conversion or the time of invocation.
See Roslyn: Convert delegate types with compatible signature automatically
Currently the various CLR compilers do not permit treating one delegate of a specific signature as the same as another delegate of an identical signature. The compilers that do (VB.NET) do so by wrapping the existing delegate instance with the new delegate which incurs a performance penalty at the time of invocation.
It appears that for whatever reason, accidentally or otherwise, the CLR/JIT have no real issue using one delegate in place of another. The verifier does complain that an unexpected type is on the stack for the specified call but otherwise the program does execute.
I propose that the verifier be modified that if the type expected and the type on the stack are different but are both delegate types, and that the
Invokemethod on both delegates share the same signature that the verifier allow the operation.This would permit delegates of identical signatures to be considered equivalent without the performance penalty either at the time of conversion or the time of invocation.