runtime: AndroidStripILAfterAOT causing "InvalidProgramException: Invalid IL code in Xunit.Assert:True(bool)"
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
VS 2022 17.8.5
Description
When setting AndroidStripILAfterAOT=true in a test app, some tests are failing the first time we run them, but then they’ll pass if we run them again.
The error is 100% reproducible when starting the app again.
Here is the error: InvalidProgramException: Invalid IL code in Xunit.Assert:True(bool): method body is empty.
No issue in Debug. No issue when removing AndroidStripILAfterAOT=true.
This is similar to dotnet/runtime#104156, but no BroadcastReceiver is involved here.
Steps to Reproduce
- Open repro in visual studio.
- Run app in Release on android emulator.
- Run all tests: one of the test fails.
- Run all tests again: both tests succeed.
Did you find any workaround?
Remove AndroidStripILAfterAOT=true.
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 31 (16 by maintainers)
@tipa yea that looks related.
Our next steps here are to wait for this fix to flow to the Android and ios SDKs and to get some performance benchmarks. If there is negligible performance impact on non-racy code we will try to do a net8.0 backport.
I’ve just tested net9-pre7. The fix works on my repro project. Thx.
The fix to this issue is on track to be shipped as part of .NET9 Preview7. Additionally, I’ve opened an PR to backport this fix to .NET8.
Fun news - I believe I can get the same failure on iOS too https://github.com/lambdageek/maui-aot-race
The underlying issue is how
mono_aot_get_methodraces withload_aot_module- one thread could attempt to readMonoImage:aot_modulewhile the other thread is still loading the aot module.@fanyang-mono I’ve added the
net8.0-iostarget to the repro. I do not have any issue with it : tests are running fine. But, is there actually an equivalent forAndroidStripILAfterAOTon iOS ?Yes, working on it.
@tranb3r I was caught up by some other projects. Will find some time to look into this this week. Sorry about the delay.
@tranb3r I was able to reproduce with the apk file that you provided. Will look into it.