-
Notifications
You must be signed in to change notification settings - Fork 572
[Mono.Android] Root Mono.Android.Export from the [Export]/[ExportField] loader, not the attributes #11804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Mono.Android] Root Mono.Android.Export from the [Export]/[ExportField] loader, not the attributes #11804
Changes from all commits
c1f136f
35489d9
98e0128
18db45c
002093e
c1214ef
ff1b627
52f2ca4
d4c3b16
117fc46
ffeaf45
1863854
a02928f
058569e
d99cf6a
558f094
a3cb051
ca5dc52
1c94329
debe97a
26aab7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,7 @@ IntPtr GetRegisterJniNativesFnPtr () => | |
| [UnmanagedCallConv (CallConvs = new[] { typeof (CallConvCdecl) })] | ||
| private static unsafe partial void xamarin_app_init (IntPtr env, delegate* unmanaged <int, int, int, IntPtr*, void> get_function_pointer); | ||
|
|
||
| [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "The AndroidTypeManager branch is only reached when RuntimeFeature.TrimmableTypeMap is false; the linker substitutes the feature switch and trims this branch in trimmable apps.")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 💡 Trimmer/AOT — This method-level Rule: Trimming suppressions should be minimal and scoped to the actual warning site |
||
| internal static JniRuntime.JniTypeManager CreateTypeManager (JnienvInitializeArgs args) | ||
| { | ||
| if (RuntimeFeature.TrimmableTypeMap) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace Java.Interop; | ||
|
|
||
| #if !JCW_ONLY_TYPE_NAMES | ||
| public | ||
| #endif // !JCW_ONLY_TYPE_NAMES | ||
| abstract class BaseExportAttribute : Attribute | ||
| { | ||
| internal abstract Delegate CreateDynamicCallback (MethodInfo method); | ||
|
|
||
| static MethodInfo? dynamic_callback_gen; | ||
|
|
||
| private protected static Delegate CreateDynamicCallbackCore (MethodInfo method) | ||
| { | ||
| // We're loading the Mono.Android.Export assembly dynamically to avoid problems with circular dependencies. | ||
| // The Type.GetType (...)?.GetMethod (...) call is chained intentionally: the trimmer only recognizes the | ||
| // GetMethod intrinsic when the constant Type value flows directly into it, so routing it through a local breaks dataflow. | ||
| dynamic_callback_gen ??= Type.GetType ("Java.Interop.DynamicCallbackCodeGenerator, Mono.Android.Export")?.GetMethod ("Create") | ||
| ?? throw new InvalidOperationException ("To use methods marked with [Export] or [ExportField], Mono.Android.Export.dll must be referenced by the application and contain a matching Java.Interop.DynamicCallbackCodeGenerator.Create method."); | ||
|
|
||
| return (Delegate?)dynamic_callback_gen.Invoke (null, [method]) | ||
| ?? throw new InvalidOperationException (FormattableString.Invariant ($"Unable to create dynamic callback for method '{method.Name}' on type '{method.DeclaringType?.FullName}'")); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 Error handling — This guard fires for both
[Export]and[ExportField]methods (the__export__connector is emitted for both, andBaseExportAttributeis their shared base), but the message only names[Export].BaseExportAttribute.CreateDynamicCallbackCorealready phrases its diagnostic as "[Export] or [ExportField]"; consider matching that here so an[ExportField]failure isn't misdiagnosed.Rule: Keep error diagnostics accurate and consistent