[CoreCLR] Dynamically build custom delegate types to support [Export] #10503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #10472
Supersedes #10493 and dotnet/java-interop#1364
The problem is that the Marshal.GetFunctionPointerForDelegate method does not work with delegates with generic types, such as
Action<...>orFunc<...>(context: dotnet/runtime#32963), which was the case of all the delegates created inMono.Android.ExportthroughDynamicMethod.This PR replaces the use of these generic delegate types with dynamically built non-generic types. It is based on an existing implementation in java-interop (see https://github.com/dotnet/java-interop/blob/02bceb03f7c07858590d930ef507745a88200a48/src/Java.Interop.Export/Java.Interop/MarshalMemberBuilder.cs#L274-L311). The CoreCLR is able to marshal the delegates built with these types to function pointers just fine.
In a previous attempt at fixing this issue (#10493), I chose a solution which modified the shape of
JniNativeMethodRegistrationwhich would be an ABI breaking change (dotnet/java-interop#1364). This implementation is much simpler and doesn't cause the same problem. Thanks to @jonpryor for steering me in this direction./cc @jonathanpeppers @grendello