-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[mono] Preserve FirstChanceExceptionEventArgs ctor #68235
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
Conversation
The runtime is creating the exception so we need to preserve it. See dotnet/android#6626
We try to avoid using descriptors if possible. I think a better fix would be to add it as DynamicDependencyAttribute to
|
@marek-safar I tried but it doesn't compile:
|
Looks like bad API design but it should be possible to use the underlying target. Try this instead [field: DynamicDependency ()] |
@marek-safar that worked :) I switched over UnhandledExceptionEventArgs too |
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2196008785 |
The runtime is creating the exception so we need to preserve it. See dotnet/android#6626 While looking at this I noticed that `FirstChanceExceptionEventArgs` is in ExceptionNotification.cs for some reason, fixed the filename to match the type name. Use DynamicDependency for preserving `FirstChanceExceptionEventArgs` and `UnhandledExceptionEventArgs`
) Fixes: #6626 Context: dotnet/runtime#68235 If you create a .NET 6 app whichs ubscribes to the [`AppDomain.FirstChanceException`][0] event: partial class MainActivity { protected override void OnCreate (Bundle? savedInstanceState) { AppDomain.CurrentDomain.FirstChanceException += (o, e) => { Console.WriteLine ("First chance exception!"); }; } } and has a way to cause an exception to be thrown: partial class MainActivity { public override void OnBackPressed() => throw new Exception ("wee?"); } and is built in Release configuration with Trimming enabled, then the app will crash when the exception is thrown (in the above case, by launching the app and then pressing the Back button): E companyname.fo: * Assertion at /__w/1/s/src/mono/mono/metadata/object.c:4179, condition `ctor' not met The cause of the crash is that the linker removes the [`FirstChanceExceptionEventArgs(Exception)`][1] constructor. This was fixed in dotnet/runtime#68235 by using appropriate `[DynamicDependency]` attributes. However, this runtime fix is unlikely to be released before our next RC. Add a workaround by updating `src/Microsoft.Android.Sdk.ILLink/PreserveLists/System.Private.CoreLib.xml` so that the linker won't remove the `FirstChanceExceptionEventArgs(Exception)` constructor. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.firstchanceexception?view=net-6.0 [1]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.exceptionservices.firstchanceexceptioneventargs.-ctor?view=net-6.0
) Fixes: #6626 Context: dotnet/runtime#68235 If you create a .NET 6 app whichs ubscribes to the [`AppDomain.FirstChanceException`][0] event: partial class MainActivity { protected override void OnCreate (Bundle? savedInstanceState) { AppDomain.CurrentDomain.FirstChanceException += (o, e) => { Console.WriteLine ("First chance exception!"); }; } } and has a way to cause an exception to be thrown: partial class MainActivity { public override void OnBackPressed() => throw new Exception ("wee?"); } and is built in Release configuration with Trimming enabled, then the app will crash when the exception is thrown (in the above case, by launching the app and then pressing the Back button): E companyname.fo: * Assertion at /__w/1/s/src/mono/mono/metadata/object.c:4179, condition `ctor' not met The cause of the crash is that the linker removes the [`FirstChanceExceptionEventArgs(Exception)`][1] constructor. This was fixed in dotnet/runtime#68235 by using appropriate `[DynamicDependency]` attributes. However, this runtime fix is unlikely to be released before our next RC. Add a workaround by updating `src/Microsoft.Android.Sdk.ILLink/PreserveLists/System.Private.CoreLib.xml` so that the linker won't remove the `FirstChanceExceptionEventArgs(Exception)` constructor. [0]: https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.firstchanceexception?view=net-6.0 [1]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.exceptionservices.firstchanceexceptioneventargs.-ctor?view=net-6.0
The runtime is creating the exception so we need to preserve it.
See dotnet/android#6626
While looking at this I noticed that
FirstChanceExceptionEventArgs
is in ExceptionNotification.cs for some reason, fixed the filename to match the type name.Use DynamicDependency for preserving
FirstChanceExceptionEventArgs
andUnhandledExceptionEventArgs