Open boxofyellow opened 7 months ago
Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.
I created this that shows some of the more odd behavior I have been seeing
https://github.com/boxofyellow/DelegateForGenericMethodExample
The exception is probably coming from here: https://github.com/dotnet/runtime/blob/9b57a265c7efd3732b035bade005561a04767128/src/coreclr/vm/comdelegate.cpp#L870-L874
I think you are right @MichalPetryka, I checked in my the demo app and it looks like this problems effects all virtual generic methods.
@jkotas are GVM delegates supposed to not be implemented in CoreCLR?
Worth to note that this doesn't repro on NativeAOT.
@jkotas are GVM delegates supposed to not be implemented in CoreCLR?
My guess is that it was not done because it is non-trivial to implement.
If we were to implement it, we should discuss the implementation approach first.
Description
If you have an interface declared as
And a delegate declared as
Attempting to create an instance of that delegate with this will throw a
NotSupportedException
However if you instead use a non-generic method (of corse
MakeGenericMethod
won't be needed) but it will be able to create an instance of the deligte. Additionally if you define a new a class with a generic method that has the same signature, and a delegate for that class's method you will be able to use similar code create an instance of that delegate.Reproduction Steps
I tried this in dotnet 6.0.420 and 8.0.203
Expected behavior
The above program can be run without an exception.
Actual behavior
Regression?
I have only tried 6.0 and 8.0 and the behavior seems to be the same in both.
Known Workarounds
One workaround I have found is to use a
DynamicMethod
to create a method to invoke the generic method. It seems to work for very simple cases. However implementing that for arbitrary method signatures might tricky.Configuration
Other information
🤷