dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Exception Not Handled in RELEASE build After "Ping" under .NET 8 MAUI (Android) #107400

Open DAConsulting opened 2 months ago

DAConsulting commented 2 months ago

Description

Exceptions generated by the system are not "caught" in a release build of an Android MAUI application, IF System.Net.NetworkInformation.Ping is used. Instead, the catch handler is never called and the application abends and quits. Note that it is not necessary for the background thread to be running to cause this issue when the exception occurs. If the background thread was run once, then stopped, the problem will still occur.

Steps to Reproduce

  1. Download the ZIP file containing the demo app from the link below.
  2. Unzip and build a RELEASE version of the app on an Android device.
  3. Press the button to force an exception a few times. This will generate a null reference exception.
  4. You should see an alert displayed from the catch() block of the exception handler in the code.
  5. Now press the button to start a thread that uses "Ping" (background thread).
  6. Press the button to force the exception again, after having started the background thread
  7. This time, the catch() handler will never execute and the app will just abend.

UPDATE!!! It is not necessary to run Ping on a background thread to cause this error. Simply calling Ping once will cause subsequent error handling to fail. So this some sort of bug in Ping.

Link to public reproduction project repository

https://drive.google.com/file/d/1mCSkiVGwSh3aHpwCZXhUb-AvEo4QNttv/view?usp=sharing

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 31 Targeted

Did you find any workaround?

Only workaround is to NOT use the Ping class in the background thread.

Bjuild logs are attached here, since there is no way to upload from "Relevant log output" below.

TestException_Release_Build_Logs.zip

Relevant log output

No response

github-actions[bot] commented 2 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

ninachen03 commented 2 months ago

This issue has been verified using latest Visual Studio 17.12.0 Preview 1.0 (8.0.82) & 17.11.2 NET7 7.0.101, Can repro on Android platform

drasticactions commented 2 months ago

I don't believe this will be a MAUI UI issue, it seems like a runtime bug, @jonathanpeppers What do you think?

jonathanpeppers commented 2 months ago

Yes, System.Net.NetworkInformation.Ping, so moving to dotnet/runtime.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

simonrozsival commented 1 month ago

This could be related to https://github.com/dotnet/runtime/issues/97209