Commit 5ccd09d
committed
[Xamarin.Android.Build.Tasks] disable Switch.System.Reflection.ForceInterpretedInvoke
Fixes: dotnet/runtime#83893
In .NET 8, `System.Reflection.ConstructorInfo/MethodInfo.Invoke()` will
call `System.Reflection.Emit` when called more than once. This impacts
startup in mobile applications, so it may not be a desired feature.
Unfortunately, this appears to happen quite easily in Android apps,
some examples:
* https://gist.github.com/ivanpovazan/2563ea9d2fea320e6425cfcc58da3ee5
* https://gist.github.com/ivanpovazan/d2546d4abad17900d4366cc29e1689b2
The types of situations this happens:
* You call a Java method from C# that returns a `Java.Lang.Object`
subclass.
* You override a Java method in C#, that has a `Java.Lang.Object`
parameter.
To solve this problem, we can set:
<ItemGroup>
<RuntimeHostConfigurationOption Include="Switch.System.Reflection.ForceInterpretedInvoke" Value="$(_SystemReflectionForceInterpretedInvoke)" Trim="true" />
</ItemGroup>
And we can set `$(_SystemReflectionForceInterpretedInvoke)` to test
out the setting in various apps.
I also updated the `.aotprofile` to verify that all
`System.Reflection.Emit` code paths disappear from `dotnet new
android` applications.1 parent 7473928 commit 5ccd09d
File tree
3 files changed
+36
-79
lines changed- src
- Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets
- profiled-aot
3 files changed
+36
-79
lines changedLines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
124 | 130 | | |
Binary file not shown.
0 commit comments